Allways get next upcoming event!?

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!

Moderator: General Moderators

Post Reply
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Allways get next upcoming event!?

Post by jmansa »

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!

Code: Select all

$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...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

is date already a column name? if so, you can only retrieve it once (with the *) - try a different variable name like `dmyDate`
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Code: Select all

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.
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Post by jmansa »

I tryid with this but with no luck.

Code: Select all

$query="SELECT * FROM calendar WHERE date > NOW() LIMIT 1";
I have done this before, but in asp... My code looked like this then!?!?

Code: Select all

strSQL = "SELECT TOP 1  calendar.*, calender.date FROM calendar WHERE (((calender.date)>=Date())) ORDER BY calender.date;"
I don't want to go back to asp... Please help... Can't see my eeror?!?!
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

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.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

works fine with a DATE type field.

also running

Code: Select all

SELECT NOW() FROM dual;
see what that returns.

Also tested against a DATETIME field, worked fine.

We are all talking about MySQL aren't we?
Post Reply