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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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