Jump to content

seperating mysql results


Woodburn2006

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
Link to comment
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.
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.