What is the best way to go about grouping rows by the same timestamp?
Posted
by Luke
on Stack Overflow
See other posts from Stack Overflow
or by Luke
Published on 2010-06-04T19:54:53Z
Indexed on
2010/06/05
10:12 UTC
Read the original article
Hit count: 195
Hello all. I am looking for some advice. I have rows of data in the database that i want to group together. There is a timestamp involved.
That column is called date. What is the best way to go about grouping rows by the same timestamp.
EDITED.....
<?
$result = mysql_query("SELECT * FROM ".TBL_FIXTURES." ORDER BY date");
$current_week = null;
while ($row = mysql_fetch_assoc($result))
{
if ($row['date'] != $current_week)
{
$current_week = $row['date'];
echo 'Week ' . $current_week .': ';
}
echo $row['home_user'];
echo $row['home_team'];
echo $row['away_user'];
echo $row['away_team'];
}
?>
I have this code. What i am trying to do is organise each round of fixtures in a row with a title Week 1 - date.
I want Week 1 and the date and all fixtures with that date displayed. Then move onto week 2 and the date and all fixtures again.
This should be done for every fixture in the database, so if there are 6 rounds of fixtures, there will be 6 dates and therefore 6 blocks of fixtures..
Please help, thanks
© Stack Overflow or respective owner