Jump to content

Displaying Ordered


Woodburn2006

Recommended Posts

im doing a website for a university football team and want to be able to list the fixtures in blocks of the team.

 

i use this code to get the fixtures from the database: SELECT * FROM fixtures ORDER BY team, month, date

 

how can i do it so that the first team fixtures are in one block, the second team is in one block etc etc. so that hopefully it will look something like this:

 

First Team

1/1 Man Utd

2/1 Chelsea

3/10 Arsenal

 

Second Team

2/4 Bolton

6/7 Derby

 

etc etc

Link to comment
https://forums.phpfreaks.com/topic/68503-displaying-ordered/
Share on other sites

if we assume this is a list of team name followed by list of dates for the that team, you'd

 

SELECT * FROM fixtures ORDER BY team, month, date

 

Then loop over the results, keeping track of the current team, for instance:

 

$current_team = "";
while ($line = mysql_fetch_assoc($result)) {
   $team = $line['team_name'];
   $t_date = $line['team_date'];
   if ($team != $current_team) {
       if ($current_team > "") {
           echo "<P>"; // Paragraph break between teams
       }
       echo "$team<BR>";
       $current_team = $team;
   }
   echo "$t_date<BR>";
}

Link to comment
https://forums.phpfreaks.com/topic/68503-displaying-ordered/#findComment-344393
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.