Jump to content

Archived

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

Woodburn2006

seperating mysql results

Recommended Posts

i am trying to do a script where the php page compares the dates from a database with todays date and then either puts the result into past or present. this is the code i have so far:

[code]while ($row = mysql_fetch_array($rsup, MYSQL_NUM))
    {
   $date = $row[0]; //first result
   $ex = $row[1]; // second result
   
   $d = split("-",$date);
   $date_seconds = mktime(0,0,0,$d[0],$d[1],$d[2]); //turn $date into seconds since jan 1, 1970
   if ($date_seconds > $today){echo "$date - $ex<br>";}
   
   echo "Past Events";
   
   if ($date_seconds < $today){echo "$date - $ex<br>";}
}[/code]

but as it is in a while loop i find that it prints 'past events' once for every result returned. so if there is 5 results it will print past events 5 times

is there any way i can seperate them easily with it only printing past events once?

i have tried using 2 while loops but i found the second one does not work, seems as if i can only use one mysql_fetch_array

thanks

Share this post


Link to post
Share on other sites
You are going to have to either put the results into an array with the value in $date_seconds as one of the fields, and sort the array on that field to group the results by the date, or redesign your database so that you have a column with the date stored as a timestamp, then you can just add "ORDER BY your_date_column DESC" onto the end of your query.

Share this post


Link to post
Share on other sites

×

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.