By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,116 Members | 1,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,116 IT Pros & Developers. It's quick & easy.

Help a script with giving more detail.

P: 19
Hey all..
I have a script im working on where i need to have listed points to show most to least in each division. Can someone help? Thanks in advance...

Expand|Select|Wrap|Line Numbers
  1. <div id='standings-east'>
  2.  
  3.             <div id='standings-east-h'></div>
  4.  
  5.             <table class='standings'>
  6.  
  7.                 <tr class='dheader'><td colspan='16'>ATLANTIC DIVISION</td></tr>
  8.  
  9.                 <tr class='theader'>
  10.  
  11.                     <td class='smH'>TEAMS</td>
  12.  
  13.                     <td class='tm'></td>
  14.  
  15.                     <td class='gp'>GP</td>
  16.  
  17.  
  18.  
  19.                     <td class='rec'>W-L-OTL</td>
  20.  
  21.                     <td class='ptsBLD'>PTS</td>
  22.  
  23.                 </tr>
  24.  
  25.  
  26.  
  27.                 <?php $x = 0; foreach (index_team_stats('Atlantic') as $stat) { ?>
  28.  
  29.                         <tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
  30.  
  31.                             <td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
  32.  
  33.                             <td class='tm'> <a href='teams/index.php?tid=<?php echo $stat['teamid']; ?>&sid=2012'><?php echo $stat['team']; ?></a></td>
  34.  
  35.                             <td class='gp'><?php echo $stat['gp']; ?></td>
  36.  
  37.  
  38.  
  39.                             <td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
  40.  
  41.                             <td class='ptsBLD'><?php echo $stat['p']; ?></td>
  42.  
  43.                         </tr>
  44.  
  45.                 <?php $x++; } ?>
  46.  
  47.  
  48.  
  49.             </table>
  50.  
  51.             <table class='standings'>
  52.  
  53.                 <tr class='dheader'><td colspan='16'>NORTHEAST DIVISION</td></tr>
  54.  
  55.                 <tr class='theader'>
  56.  
  57.  
  58.  
  59.                     <td class='smH'>TEAMS</td>
  60.  
  61.                     <td class='tm'></td>
  62.  
  63.                     <td class='gp'>GP</td>
  64.  
  65.                     <td class='rec'>W-L-OTL</td>
  66.  
  67.                     <td class='ptsBLD'>PTS</td>
  68.  
  69.                 </tr>
  70.  
  71.                 <?php $x = 0; foreach (index_team_stats('Northeast') as $stat) { ?>
  72.  
  73.                         <tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
  74.  
  75.                             <td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
  76.  
  77.                             <td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
  78.  
  79.                             <td class='gp'><?php echo $stat['gp']; ?></td>
  80.  
  81.  
  82.  
  83.                             <td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
  84.  
  85.                             <td class='ptsBLD'><?php echo $stat['p']; ?></td>
  86.  
  87.                         </tr>
  88.  
  89.                 <?php $x++; } ?>
  90.  
  91.             </table>
  92.  
  93.             <table class='standings-b'>
  94.  
  95.                 <tr class='dheader'><td colspan='16'>SOUTHEAST DIVISION</td></tr>
  96.  
  97.                 <tr class='theader'>
  98.  
  99.                     <td class='smH'>TEAMS</td>
  100.  
  101.                     <td class='tm'></td>
  102.  
  103.                     <td class='gp'>GP</td>
  104.  
  105.  
  106.  
  107.                     <td class='rec'>W-L-OTL</td>
  108.  
  109.                     <td class='ptsBLD'>PTS</td>
  110.  
  111.                 </tr>
  112.  
  113.                 <?php $x = 0; foreach (index_team_stats('Southeast') as $stat) { ?>
  114.  
  115.                         <tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
  116.  
  117.                             <td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
  118.  
  119.                             <td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
  120.  
  121.                             <td class='gp'><?php echo $stat['gp']; ?></td>
  122.  
  123.  
  124.  
  125.                             <td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
  126.  
  127.                             <td class='ptsBLD'><?php echo $stat['p']; ?></td>
  128.  
  129.                         </tr>
  130.  
  131.                 <?php $x++; } ?>
  132.  
  133.             </table>
  134.  
  135.         </div>
  136.  
  137.  
  138.  
  139.         <div id='standings-west'>
  140.  
  141.             <div id='standings-west-h'></div>
  142.  
  143.  
  144.  
  145.             <table class='standings'>
  146.  
  147.                 <tr class='dheader'><td colspan='16'>CENTRAL DIVISION</td></tr>
  148.  
  149.                 <tr class='theader'>
  150.  
  151.                     <td class='smH'>TEAMS</td>
  152.  
  153.                     <td class='tm'></td>
  154.  
  155.                     <td class='gp'>GP</td>
  156.  
  157.                     <td class='rec'>W-L-OTL</td>
  158.  
  159.  
  160.  
  161.                     <td class='ptsBLD'>PTS</td>
  162.  
  163.                 </tr>
  164.  
  165.                 <?php $x = 0; foreach (index_team_stats('Central') as $stat) { ?>
  166.  
  167.                         <tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
  168.  
  169.                             <td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
  170.  
  171.                             <td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
  172.  
  173.                             <td class='gp'><?php echo $stat['gp']; ?></td>
  174.  
  175.  
  176.  
  177.                             <td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
  178.  
  179.                             <td class='ptsBLD'><?php echo $stat['p']; ?></td>
  180.  
  181.                         </tr>
  182.  
  183.                 <?php $x++; } ?>
  184.  
  185.             </table>
  186.  
  187.             <table class='standings'>
  188.  
  189.                 <tr class='dheader'><td colspan='16'>NORTHWEST DIVISION</td></tr>
  190.  
  191.                 <tr class='theader'>
  192.  
  193.                     <td class='smH'>TEAMS</td>
  194.  
  195.  
  196.  
  197.                     <td class='tm'></td>
  198.  
  199.                     <td class='gp'>GP</td>
  200.  
  201.                     <td class='rec'>W-L-OTL</td>
  202.  
  203.                     <td class='ptsBLD'>PTS</td>
  204.  
  205.                 </tr>
  206.  
  207.                 <?php $x = 0; foreach (index_team_stats('Northwest') as $stat) { ?>
  208.  
  209.                         <tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
  210.  
  211.                             <td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
  212.  
  213.                             <td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
  214.  
  215.                             <td class='gp'><?php echo $stat['gp']; ?></td>
  216.  
  217.  
  218.  
  219.                             <td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
  220.  
  221.                             <td class='ptsBLD'><?php echo $stat['p']; ?></td>
  222.  
  223.                         </tr>
  224.  
  225.                 <?php $x++; } ?>
  226.  
  227.             </table>
  228.  
  229.             <table class='standings-b'>
  230.  
  231.                 <tr class='dheader'><td colspan='16'>PACIFIC DIVISION</td></tr>
  232.  
  233.                 <tr class='theader'>
  234.  
  235.                     <td class='smH'>TEAMS</td>
  236.  
  237.                     <td class='tm'></td>
  238.  
  239.                     <td class='gp'>GP</td>
  240.  
  241.  
  242.  
  243.                     <td class='rec'>W-L-OTL</td>
  244.  
  245.                     <td class='ptsBLD'>PTS</td>
  246.  
  247.                 </tr>
  248.  
  249.                 <?php $x = 0; foreach (index_team_stats('Pacific') as $stat) { ?>
  250.  
  251.                         <tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
  252.  
  253.                             <td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
  254.  
  255.                             <td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
  256.  
  257.                             <td class='gp'><?php echo $stat['gp']; ?></td>
  258.  
  259.  
  260.  
  261.                             <td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
  262.  
  263.                             <td class='ptsBLD'><?php echo $stat['p']; ?></td>
  264.  
  265.                         </tr>
  266.  
  267.                 <?php $x++; } ?>
  268.  
  269.             </table>
  270.  
  271.         </div>
Feb 22 '12 #1
Share this Question
Share on Google+
13 Replies


Dormilich
Expert Mod 5K+
P: 8,639
you mean listed point like in an <ul>?
Feb 23 '12 #2

P: 19
Thanks for your reply Dormilich. No, i mean in the points column as shown here. Looking for the teams info to list team with highest points to lowest in order.

Feb 23 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
you would do the ordering when you fetch/process the data. e.g. in SQL you would add an ORDER BY clause
Feb 23 '12 #4

P: 19
THanks Dormilich but i am self taught and still struggle with certain code. Here is my SQL. Can you add a little light to my question?

:) Thanks again.

Expand|Select|Wrap|Line Numbers
  1. function index_team_stats($subconference) {
  2.  
  3.     $return = array();
  4.  
  5.     $query = "SELECT id, teamname, teamnameseason, teamabr FROM teams WHERE subconference = '" . $subconference . "' ORDER BY teamnameseason";
  6.  
  7.     $teams = result_array($query);
  8.  
  9.     foreach ($teams as $team) {
  10.  
  11.         $query = "SELECT gp, w, l, ol, p FROM season12 WHERE team = '" . $team['teamnameseason'] . "'";
  12.  
  13.         $results = result_array($query);
  14.  
  15.         if ($results) {
  16.  
  17.             $results[0]['team'] = str_replace($team['teamnameseason'], '', $team['teamname']);
  18.  
  19.             $results[0]['teamabr'] = $team['teamabr'];
  20.  
  21.             $results[0]['teamid'] = $team['id'];
  22.  
  23.             $return[] = $results[0];
  24.         }
  25.     }
  26.     return $return;
  27. }
Feb 23 '12 #5

Dormilich
Expert Mod 5K+
P: 8,639
Can you add a little light to my question?
a little bit.

first of all is that you don't need two queries. you can combine both tables with a JOIN command.

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.     s12.gp AS gp,
  3.  -- you would need aliases like the above for all values
  4.  -- to access the data via associative array in the result
  5.     s12.w, 
  6.     s12.l, 
  7.     s12.ol, 
  8.     s12.p,
  9.     teams.id, 
  10.     teams.teamname, 
  11.     teams.teamnameseason, 
  12.     teams.teamabr 
  13. FROM 
  14.     season12 AS s12
  15. JOIN
  16.     teams
  17.     ON s12.team = teams.teamnameseason
  18. WHERE
  19.     teams.subconference = ?
  20. ORDER BY
  21.     s12.gp
then you can fetch the data in one loop as desired. I may note that it would be more comfortable to use objects for the whole task, but I leave that for later.
Feb 23 '12 #6

P: 19
Thanks. That helps me understand abit more. Now for the fetch data this is my code but im missing something. Im getting a error.

Expand|Select|Wrap|Line Numbers
  1. function result_array($query) {
  2.  
  3.     $results = mysql_query($query);
  4.  
  5.     $return = array();
  6.  
  7.     while ($row = mysql_fetch_assoc($results)) {
  8.  
  9.         $return[] = $row;
  10.  
  11.     }
  12.  
  13.     return $return;
  14.  
  15. }
Feb 23 '12 #7

Dormilich
Expert Mod 5K+
P: 8,639
Im getting a error.
well, that possibility can never be ruled out.

(i.e. I can’t help without more details)
Feb 23 '12 #8

P: 19
Sorry Dormilich... Here is the error i am getting...

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/vhockey/public_html/vhatest/connect.php on line 104

This is line 104 --- while ($row = mysql_fetch_assoc($results)) {


Thanks again.
Feb 23 '12 #9

Dormilich
Expert Mod 5K+
P: 8,639
the usual suspect—your query failed.

try the following:
Expand|Select|Wrap|Line Numbers
  1. $results = mysql_query($query) or die("error on: " . $query . " saying: " . mysql_error());
Feb 23 '12 #10

P: 19
Well, now this is the error i get...

error on: SELECT s12.gp AS gp,s12.w,s12.l,s12.ol,s12.p,teams.id,teams.teamnam e,teams.teamnameseason,teams.teamabr FROM season12 AS s12 JOIN teams ON s12.team = t eams.teamnameseason WHERE teams.subconference =&nbs p;? ORDER BY s12.gp . saying: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'eams.teamnameseason WHERE teams.subconference =&nbs p;? ORDER BY s12.gp' at line 7


Im all confused now.. hehe..
Feb 23 '12 #11

P: 19
Here is my code as of now:

Expand|Select|Wrap|Line Numbers
  1. function index_team_stats($subconference) {
  2.  
  3.  
  4.  
  5.     $return = array();
  6.  
  7.  
  8.  
  9.     $query = "SELECT id, teamname, teamnameseason, teamabr FROM teams WHERE subconference = '" . $subconference . "' ORDER BY teamnameseason";
  10.  
  11.  
  12.  
  13.     $teams = result_array($query);
  14.  
  15.  
  16.  
  17.     foreach ($teams as $team) {
  18.  
  19.  
  20.  
  21.         $query = "SELECT s12.gp AS gp,s12.w,s12.l,s12.ol,s12.p,teams.id,teams.teamname,teams.teamnameseason,teams.teamabr 
  22. FROM 
  23.     season12 AS s12
  24. JOIN
  25.     teams
  26.     ON s12.team = t
  27. eams.teamnameseason
  28. WHERE
  29.     teams.subconference =&nbs
  30. p;?
  31.  
  32. ORDER BY
  33.     s12.gp . ";
  34.  
  35.  
  36.  
  37.         $results = result_array($query);
  38.  
  39.  
  40.  
  41.         if ($results) {
  42.  
  43.  
  44.  
  45.             $results[0]['team'] = str_replace($team['teamnameseason'], '', $team['teamname']);
  46.  
  47.             $results[0]['teamabr'] = $team['teamabr'];
  48.  
  49.             $results[0]['teamid'] = $team['id'];
  50.  
  51.  
  52.  
  53.             $return[] = $results[0];
  54.  
  55.  
  56.  
  57.         }
  58.  
  59.  
  60.  
  61.     }
  62.  
  63.  
  64.  
  65.     return $return;
  66.  
  67.  
  68.  
  69. }
  70.  
  71.  
  72.  
  73. function get_team_name($teamnameseason) {
  74.  
  75.  
  76.  
  77.     $query = "SELECT teamname FROM teams WHERE teamnameseason = '" . $teamnameseason . "'";
  78.  
  79.  
  80.  
  81.     $row = mysql_fetch_row(mysql_query($query));
  82.  
  83.  
  84.  
  85.     return str_replace($teamnameseason, '', $row[0]);
  86.  
  87.  
  88.  
  89. }
  90.  
  91.  
  92.  
  93. function result_array($query) {
  94.  
  95.  
  96.  
  97.     $results = mysql_query($query) or die("error on: " . $query . " saying: " . mysql_error());
  98.  
  99.  
  100.  
  101.     $return = array();
  102.  
  103.  
  104.  
  105.     while ($row = mysql_fetch_assoc($results)) {
  106.  
  107.  
  108.  
  109.         $return[] = $row;
  110.  
  111.  
  112.  
  113.     }
  114.  
  115.  
  116.  
  117.     return $return;
  118.  
  119.  
  120.  
  121. }
  122.  
  123.  
  124.  
  125. ?>
Feb 23 '12 #12

Dormilich
Expert Mod 5K+
P: 8,639
there are a couple of woes.

why do you have 2 queries again?
Feb 24 '12 #13

P: 19
Hi Dormilich,
To be honest i am a disabled vet and i have someone come to my home once a week that teaches and helps me understand php code. It has been a long process but still learning. Your question of why 2 queries is well here is the whole connect page that may help u understand. This is minus the connect info.

Expand|Select|Wrap|Line Numbers
  1. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
  2.  
  3.  
  4.  
  5. mysql_select_db($dbname);
  6.  
  7.  
  8.  
  9. function index_offensive_leaders($type) {
  10.  
  11.  
  12.  
  13.     $query = 'SELECT id, first, last, ' . $type . ', team FROM regularseasonskaters12 ORDER BY ' . $type . ' DESC LIMIT 5';
  14.  
  15.  
  16.  
  17.     return result_array($query);
  18.  
  19.  
  20.  
  21. }
  22.  
  23.  
  24.  
  25. function index_goalie_leaders($type) {
  26.  
  27.  
  28.  
  29.     $query = 'SELECT id, first, last, ' . $type . ', team FROM regularseasongoalies12 ORDER BY ' . $type . ' DESC LIMIT 5';
  30.  
  31.  
  32.  
  33.     return result_array($query);
  34.  
  35.  
  36.  
  37. }
  38.  
  39.  
  40.  
  41. function index_game_results() {
  42.  
  43.  
  44.  
  45.     $query = 'SELECT id, date, concat(right(date, 4), mid(date, 4, 2), left(date, 2)) AS concat_date, home, away, homescore, awayscore FROM gamestats12 WHERE date <> \'date\' ORDER BY concat_date DESC LIMIT 20';
  46.  
  47.  
  48.  
  49.     return result_array($query);
  50.  
  51.  
  52.  
  53. }
  54.  
  55.  
  56.  
  57.  
  58. function index_team_stats($subconference) {
  59.  
  60.  
  61.  
  62.     $return = array();
  63.  
  64.  
  65.  
  66.     $query = "SELECT id, teamname, teamnameseason, teamabr FROM teams WHERE subconference = '" . $subconference . "' ORDER BY teamnameseason";
  67.  
  68.  
  69.  
  70.     $teams = result_array($query);
  71.  
  72.  
  73.  
  74.     foreach ($teams as $team) {
  75.  
  76.  
  77.  
  78.         $query = "SELECT s12.gp AS gp,s12.w,s12.l,s12.ol,s12.p,teams.id,teams.teamname,teams.teamnameseason,teams.teamabr 
  79. FROM 
  80.     season12 AS s12
  81. JOIN
  82.     teams
  83.     ON s12.team = t
  84. eams.teamnameseason
  85. WHERE
  86.     teams.subconference =&nbs
  87. p;?
  88.  
  89. ORDER BY
  90.     s12.gp . ";
  91.  
  92.  
  93.  
  94.         $results = result_array($query);
  95.  
  96.  
  97.  
  98.         if ($results) {
  99.  
  100.  
  101.  
  102.             $results[0]['team'] = str_replace($team['teamnameseason'], '', $team['teamname']);
  103.  
  104.             $results[0]['teamabr'] = $team['teamabr'];
  105.  
  106.             $results[0]['teamid'] = $team['id'];
  107.  
  108.  
  109.  
  110.             $return[] = $results[0];
  111.  
  112.  
  113.  
  114.         }
  115.  
  116.  
  117.  
  118.     }
  119.  
  120.  
  121.  
  122.     return $return;
  123.  
  124.  
  125.  
  126. }
  127.  
  128.  
  129.  
  130. function get_team_name($teamnameseason) {
  131.  
  132.  
  133.  
  134.     $query = "SELECT teamname FROM teams WHERE teamnameseason = '" . $teamnameseason . "'";
  135.  
  136.  
  137.  
  138.     $row = mysql_fetch_row(mysql_query($query));
  139.  
  140.  
  141.  
  142.     return str_replace($teamnameseason, '', $row[0]);
  143.  
  144.  
  145.  
  146. }
  147.  
  148.  
  149.  
  150. function result_array($query) {
  151.  
  152.  
  153.  
  154.     $results = mysql_query($query) or die("error on: " . $query . " saying: " . mysql_error());
  155.  
  156.  
  157.  
  158.     $return = array();
  159.  
  160.  
  161.  
  162.     while ($row = mysql_fetch_assoc($results)) {
  163.  
  164.  
  165.  
  166.         $return[] = $row;
  167.  
  168.  
  169.  
  170.     }
  171.  
  172.  
  173.  
  174.     return $return;
  175.  
  176.  
  177.  
  178. }
  179.  
  180.  
  181.  
  182. ?>
Here is my temp site location... It will be updating the old site once finished. Alot of work to be done.

www.virtualhockeyassociation.com/vhatest/index.php

Thanks for all your help.
Feb 24 '12 #14

Post your reply

Sign in to post your reply or Sign up for a free account.