Jump to content


seperating mysql results

  • Please log in to reply
1 reply to this topic

#1 Woodburn2006

  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 31 July 2006 - 11:51 AM

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:

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>";}

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


#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 31 July 2006 - 01:58 PM

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.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users