Page 1 of 1

Sorting results by time and date

Posted: Fri Sep 12, 2008 8:10 am
by goochy808
Hi

I have written a flash/php app that pulls records out of a MySQL database and populates variables in the flash movie. That it works OK but what I am trying to do is the following:

I have a series of football fixtures with a date and kick-off time. I want to be able to automatically show the next game in the list at the time it is requested but for some reason it pulls up the right date but not the right time.

How do I select the next result according to TIME and DATE?

I am using dreamweaver connecting to MySQL through PHP. What would be the correct syntax for the MySQL/PHP query?

Many thanks

Peter

Re: Sorting results by time and date

Posted: Fri Sep 12, 2008 8:15 am
by jaoudestudios
What is your current query?

Re: Sorting results by time and date

Posted: Fri Sep 12, 2008 9:48 am
by jayshields
What do you mean it pulls up the right date but not the right time?

You'll probably want to use an ORDER BY and LIMIT clause, something like this:

Code: Select all

ORDER BY 
  `date_time` DESC 
LIMIT 1

Re: Sorting results by time and date

Posted: Sat Sep 13, 2008 4:35 pm
by BETA
Mm yeah i would use NOW() and save it to a datetime table so it saves the time and date and use DATE_FORMAT(datetablename,' %d/%m/%Y, %H:%i:%s') as datevariablename FROM tablename ORDER BY DATE DESC";
hope it helps!