Help a script with giving more detail.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • syoung69
    New Member
    • Sep 2011
    • 19

    Help a script with giving more detail.

    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...

    Code:
    <div id='standings-east'>
    
    			<div id='standings-east-h'></div>
    
    			<table class='standings'>
    
    				<tr class='dheader'><td colspan='16'>ATLANTIC DIVISION</td></tr>
    
    				<tr class='theader'>
    
    					<td class='smH'>TEAMS</td>
    
    					<td class='tm'></td>
    
    					<td class='gp'>GP</td>
    
    
    
    					<td class='rec'>W-L-OTL</td>
    
    					<td class='ptsBLD'>PTS</td>
    
    				</tr>
    
    
    
    				<?php $x = 0; foreach (index_team_stats('Atlantic') as $stat) { ?>
    
    						<tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
    
    							<td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
    
    							<td class='tm'> <a href='teams/index.php?tid=<?php echo $stat['teamid']; ?>&sid=2012'><?php echo $stat['team']; ?></a></td>
    
    							<td class='gp'><?php echo $stat['gp']; ?></td>
    
    
    
    							<td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
    
    							<td class='ptsBLD'><?php echo $stat['p']; ?></td>
    
    						</tr>
    
    				<?php $x++; } ?>
    
    
    
    			</table>
    
    			<table class='standings'>
    
    				<tr class='dheader'><td colspan='16'>NORTHEAST DIVISION</td></tr>
    
    				<tr class='theader'>
    
    
    
    					<td class='smH'>TEAMS</td>
    
    					<td class='tm'></td>
    
    					<td class='gp'>GP</td>
    
    					<td class='rec'>W-L-OTL</td>
    
    					<td class='ptsBLD'>PTS</td>
    
    				</tr>
    
    				<?php $x = 0; foreach (index_team_stats('Northeast') as $stat) { ?>
    
    						<tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
    
    							<td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
    
    							<td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
    
    							<td class='gp'><?php echo $stat['gp']; ?></td>
    
    
    
    							<td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
    
    							<td class='ptsBLD'><?php echo $stat['p']; ?></td>
    
    						</tr>
    
    				<?php $x++; } ?>
    
    			</table>
    
    			<table class='standings-b'>
    
    				<tr class='dheader'><td colspan='16'>SOUTHEAST DIVISION</td></tr>
    
    				<tr class='theader'>
    
    					<td class='smH'>TEAMS</td>
    
    					<td class='tm'></td>
    
    					<td class='gp'>GP</td>
    
    
    
    					<td class='rec'>W-L-OTL</td>
    
    					<td class='ptsBLD'>PTS</td>
    
    				</tr>
    
    				<?php $x = 0; foreach (index_team_stats('Southeast') as $stat) { ?>
    
    						<tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
    
    							<td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
    
    							<td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
    
    							<td class='gp'><?php echo $stat['gp']; ?></td>
    
    
    
    							<td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
    
    							<td class='ptsBLD'><?php echo $stat['p']; ?></td>
    
    						</tr>
    
    				<?php $x++; } ?>
    
    			</table>
    
    		</div>
    
    
    
    		<div id='standings-west'>
    
    			<div id='standings-west-h'></div>
    
    
    
    			<table class='standings'>
    
    				<tr class='dheader'><td colspan='16'>CENTRAL DIVISION</td></tr>
    
    				<tr class='theader'>
    
    					<td class='smH'>TEAMS</td>
    
    					<td class='tm'></td>
    
    					<td class='gp'>GP</td>
    
    					<td class='rec'>W-L-OTL</td>
    
    
    
    					<td class='ptsBLD'>PTS</td>
    
    				</tr>
    
    				<?php $x = 0; foreach (index_team_stats('Central') as $stat) { ?>
    
    						<tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
    
    							<td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
    
    							<td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
    
    							<td class='gp'><?php echo $stat['gp']; ?></td>
    
    
    
    							<td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
    
    							<td class='ptsBLD'><?php echo $stat['p']; ?></td>
    
    						</tr>
    
    				<?php $x++; } ?>
    
    			</table>
    
    			<table class='standings'>
    
    				<tr class='dheader'><td colspan='16'>NORTHWEST DIVISION</td></tr>
    
    				<tr class='theader'>
    
    					<td class='smH'>TEAMS</td>
    
    
    
    					<td class='tm'></td>
    
    					<td class='gp'>GP</td>
    
    					<td class='rec'>W-L-OTL</td>
    
    					<td class='ptsBLD'>PTS</td>
    
    				</tr>
    
    				<?php $x = 0; foreach (index_team_stats('Northwest') as $stat) { ?>
    
    						<tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
    
    							<td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
    
    							<td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
    
    							<td class='gp'><?php echo $stat['gp']; ?></td>
    
    
    
    							<td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
    
    							<td class='ptsBLD'><?php echo $stat['p']; ?></td>
    
    						</tr>
    
    				<?php $x++; } ?>
    
    			</table>
    
    			<table class='standings-b'>
    
    				<tr class='dheader'><td colspan='16'>PACIFIC DIVISION</td></tr>
    
    				<tr class='theader'>
    
    					<td class='smH'>TEAMS</td>
    
    					<td class='tm'></td>
    
    					<td class='gp'>GP</td>
    
    
    
    					<td class='rec'>W-L-OTL</td>
    
    					<td class='ptsBLD'>PTS</td>
    
    				</tr>
    
    				<?php $x = 0; foreach (index_team_stats('Pacific') as $stat) { ?>
    
    						<tr style='background: <?php if ($x%2) { ?>#FFFFFF<?php } else { ?>#E4E4E4<?php } ?>'>
    
    							<td class='sm'><img src='images/logos/small/<?php echo strtolower($stat['teamabr']); ?>.png' class='small-logo' alt='' /></td>
    
    							<td class='tm'> <a href='teams/?tid=18&amp;sid=2012'><?php echo $stat['team']; ?></a></td>
    
    							<td class='gp'><?php echo $stat['gp']; ?></td>
    
    
    
    							<td class='rec'><?php echo $stat['w']; ?>-<?php echo $stat['l']; ?>-<?php echo $stat['ol']; ?></td>
    
    							<td class='ptsBLD'><?php echo $stat['p']; ?></td>
    
    						</tr>
    
    				<?php $x++; } ?>
    
    			</table>
    
    		</div>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you mean listed point like in an <ul>?

    Comment

    • syoung69
      New Member
      • Sep 2011
      • 19

      #3
      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.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        you would do the ordering when you fetch/process the data. e.g. in SQL you would add an ORDER BY clause

        Comment

        • syoung69
          New Member
          • Sep 2011
          • 19

          #5
          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.

          Code:
          function index_team_stats($subconference) {
          
          	$return = array();
          
          	$query = "SELECT id, teamname, teamnameseason, teamabr FROM teams WHERE subconference = '" . $subconference . "' ORDER BY teamnameseason";
          
          	$teams = result_array($query);
          
          	foreach ($teams as $team) {
          
          		$query = "SELECT gp, w, l, ol, p FROM season12 WHERE team = '" . $team['teamnameseason'] . "'";
          
          		$results = result_array($query);
          
          		if ($results) {
          
          			$results[0]['team'] = str_replace($team['teamnameseason'], '', $team['teamname']);
          
          			$results[0]['teamabr'] = $team['teamabr'];
          
          			$results[0]['teamid'] = $team['id'];
          
          			$return[] = $results[0];
          		}
          	}
          	return $return;
          }
          Last edited by Dormilich; Feb 23 '12, 04:00 PM. Reason: removing unnecessary lines

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            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.

            Code:
            SELECT 
                s12.gp AS gp,
             -- you would need aliases like the above for all values
             -- to access the data via associative array in the result
                s12.w, 
                s12.l, 
                s12.ol, 
                s12.p,
                teams.id, 
                teams.teamname, 
                teams.teamnameseason, 
                teams.teamabr 
            FROM 
                season12 AS s12
            JOIN
                teams
                ON s12.team = teams.teamnameseason
            WHERE
                teams.subconference = ?
            ORDER BY
                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.

            Comment

            • syoung69
              New Member
              • Sep 2011
              • 19

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

              Code:
              function result_array($query) {
              
              	$results = mysql_query($query);
              
              	$return = array();
              
              	while ($row = mysql_fetch_assoc($results)) {
              
              		$return[] = $row;
              
              	}
              
              	return $return;
              
              }
              Last edited by Dormilich; Feb 23 '12, 05:38 PM.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Im getting a error.
                well, that possibility can never be ruled out.

                (i.e. I can’t help without more details)

                Comment

                • syoung69
                  New Member
                  • Sep 2011
                  • 19

                  #9
                  Sorry Dormilich... Here is the error i am getting...

                  Warning: mysql_fetch_ass oc(): 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_ass oc($results)) {


                  Thanks again.

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    the usual suspect—your query failed.

                    try the following:
                    Code:
                    $results = mysql_query($query) or die("error on: " . $query . " saying: " . mysql_error());

                    Comment

                    • syoung69
                      New Member
                      • Sep 2011
                      • 19

                      #11
                      Well, now this is the error i get...

                      error on: SELECT s12.gp AS gp,s12.w,s12.l, s12.ol,s12.p,te ams.id,teams.te amname,teams.te amnameseason,te ams.teamabr FROM season12 AS s12 JOIN teams ON s12.team = t eams.teamnamese ason WHERE teams.subconfer ence =&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.teamnames eason WHERE teams.subconfer ence =&nbs p;? ORDER BY s12.gp' at line 7


                      Im all confused now.. hehe..

                      Comment

                      • syoung69
                        New Member
                        • Sep 2011
                        • 19

                        #12
                        Here is my code as of now:

                        Code:
                        function index_team_stats($subconference) {
                        
                        
                        
                        	$return = array();
                        
                        
                        
                        	$query = "SELECT id, teamname, teamnameseason, teamabr FROM teams WHERE subconference = '" . $subconference . "' ORDER BY teamnameseason";
                        
                        
                        
                        	$teams = result_array($query);
                        
                        
                        
                        	foreach ($teams as $team) {
                        
                        
                        
                        		$query = "SELECT s12.gp AS gp,s12.w,s12.l,s12.ol,s12.p,teams.id,teams.teamname,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 . ";
                        
                        
                        
                        		$results = result_array($query);
                        
                        
                        
                        		if ($results) {
                        
                        
                        
                        			$results[0]['team'] = str_replace($team['teamnameseason'], '', $team['teamname']);
                        
                        			$results[0]['teamabr'] = $team['teamabr'];
                        
                        			$results[0]['teamid'] = $team['id'];
                        
                        
                        
                        			$return[] = $results[0];
                        
                        
                        
                        		}
                        
                        
                        
                        	}
                        
                        
                        
                        	return $return;
                        
                        
                        
                        }
                        
                        
                        
                        function get_team_name($teamnameseason) {
                        
                        
                        
                        	$query = "SELECT teamname FROM teams WHERE teamnameseason = '" . $teamnameseason . "'";
                        
                        
                        
                        	$row = mysql_fetch_row(mysql_query($query));
                        
                        
                        
                        	return str_replace($teamnameseason, '', $row[0]);
                        
                        
                        
                        }
                        
                        
                        
                        function result_array($query) {
                        
                        
                        
                        	$results = mysql_query($query) or die("error on: " . $query . " saying: " . mysql_error());
                        
                        
                        
                        	$return = array();
                        
                        
                        
                        	while ($row = mysql_fetch_assoc($results)) {
                        
                        
                        
                        		$return[] = $row;
                        
                        
                        
                        	}
                        
                        
                        
                        	return $return;
                        
                        
                        
                        }
                        
                        
                        
                        ?>

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          there are a couple of woes.

                          why do you have 2 queries again?

                          Comment

                          • syoung69
                            New Member
                            • Sep 2011
                            • 19

                            #14
                            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.

                            Code:
                            $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
                            
                            
                            
                            mysql_select_db($dbname);
                            
                            
                            
                            function index_offensive_leaders($type) {
                            
                            
                            
                            	$query = 'SELECT id, first, last, ' . $type . ', team FROM regularseasonskaters12 ORDER BY ' . $type . ' DESC LIMIT 5';
                            
                            
                            
                            	return result_array($query);
                            
                            
                            
                            }
                            
                            
                            
                            function index_goalie_leaders($type) {
                            
                            
                            
                            	$query = 'SELECT id, first, last, ' . $type . ', team FROM regularseasongoalies12 ORDER BY ' . $type . ' DESC LIMIT 5';
                            
                            
                            
                            	return result_array($query);
                            
                            
                            
                            }
                            
                            
                            
                            function index_game_results() {
                            
                            
                            
                            	$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';
                            
                            
                            
                            	return result_array($query);
                            
                            
                            
                            }
                            
                            
                                
                            
                            function index_team_stats($subconference) {
                            
                            
                            
                            	$return = array();
                            
                            
                            
                            	$query = "SELECT id, teamname, teamnameseason, teamabr FROM teams WHERE subconference = '" . $subconference . "' ORDER BY teamnameseason";
                            
                            
                            
                            	$teams = result_array($query);
                            
                            
                            
                            	foreach ($teams as $team) {
                            
                            
                            
                            		$query = "SELECT s12.gp AS gp,s12.w,s12.l,s12.ol,s12.p,teams.id,teams.teamname,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 . ";
                            
                            
                            
                            		$results = result_array($query);
                            
                            
                            
                            		if ($results) {
                            
                            
                            
                            			$results[0]['team'] = str_replace($team['teamnameseason'], '', $team['teamname']);
                            
                            			$results[0]['teamabr'] = $team['teamabr'];
                            
                            			$results[0]['teamid'] = $team['id'];
                            
                            
                            
                            			$return[] = $results[0];
                            
                            
                            
                            		}
                            
                            
                            
                            	}
                            
                            
                            
                            	return $return;
                            
                            
                            
                            }
                            
                            
                            
                            function get_team_name($teamnameseason) {
                            
                            
                            
                            	$query = "SELECT teamname FROM teams WHERE teamnameseason = '" . $teamnameseason . "'";
                            
                            
                            
                            	$row = mysql_fetch_row(mysql_query($query));
                            
                            
                            
                            	return str_replace($teamnameseason, '', $row[0]);
                            
                            
                            
                            }
                            
                            
                            
                            function result_array($query) {
                            
                            
                            
                            	$results = mysql_query($query) or die("error on: " . $query . " saying: " . mysql_error());
                            
                            
                            
                            	$return = array();
                            
                            
                            
                            	while ($row = mysql_fetch_assoc($results)) {
                            
                            
                            
                            		$return[] = $row;
                            
                            
                            
                            	}
                            
                            
                            
                            	return $return;
                            
                            
                            
                            }
                            
                            
                            
                            ?>
                            Here is my temp site location... It will be updating the old site once finished. Alot of work to be done.



                            Thanks for all your help.

                            Comment

                            Working...