Jump to content

[SOLVED] dates


phorcon3

Recommended Posts

MySQL Table

 

id

subject

time

1

subject 1

timestamp

2

subject 2

timestamp

3

subject 3

timestamp

 

and what I wanna do is group it by dates, so it would look somewhat like this

 

February 3, 2008

- subject 3

- subject 2

 

February 2, 2008

- subject 1

 

for example? anyone know how to do this?

Link to comment
https://forums.phpfreaks.com/topic/90048-solved-dates/
Share on other sites

that will be in yer php code.

 

before the loop create a prevdate - leave empty,

in the loop, compare prevdate with row's timestamp

if different, print out the date, save the new prevdate

print the info

and loop

 

$prevdate=''
$while($row=mysql_fetch_assoc($res))
{
   if($prevdate != $row['ts'])
  {
     echo "Date: " . gmdate("Y-m-d",$row['ts']) . "<br>";
    $prevdate=$row['ts'];
  }
   echo "$row[id]) $row[subject]<br>";
}

Link to comment
https://forums.phpfreaks.com/topic/90048-solved-dates/#findComment-461693
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.