Woodburn2006 Posted July 31, 2006 Share Posted July 31, 2006 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 timesis 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_arraythanks Quote Link to comment Share on other sites More sharing options...
king arthur Posted July 31, 2006 Share Posted July 31, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.