PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
How can I allways only get the next comming date/event from my calender.
Lets say that today is 23-3-07 and the next event is 27-3-07. Right now it prints only the first event in my calendar but I want to show the next coming event from the db when the date from the first has surpassed!
$query="SELECT *, DATE_FORMAT(date, '%d-%m%-%Y') AS date FROM calendar WHERE date > NOW() LIMIT 1";
/*$query="SELECT * FROM calendar";*/
$result=mysql_query($query);
$calendar = mysql_fetch_array($result);
I tryid this but with no luck... Where is my error? Can anybody please help...
SELECT *, DATE_FORMAT(date, '%d-%m%-%Y') AS date FROM calendar WHERE date > NOW() LIMIT 1
You are formatting the date before comparision in the query. i.e at date>NOW()
what happens here is your date comes 12-02-2006(will be some number mysql db calculates it to be)>2006-02-13(someother number).
Your comparision goes wrong.
How are you storing 'date'? [s]NOW() will return a unix timestamp, and won't work with DATETIME types or any non-standard string representation.[/s] NOW() will return a value compatible with DATETIME, not with a unix timestamp. (thanks for the correction, mikeq)
Last edited by aaronhall on Sat Mar 24, 2007 5:41 am, edited 1 time in total.