Page 1 of 1

SELECT * Statement Question

Posted: Tue Dec 05, 2006 11:44 am
by $var
hi, i have used this idea in the past, but perhaps there has been a change from php4 to 5 that doesn't like this statement:

Code: Select all

$today= date("Y-m-d");
   $cityID = $_GET["cityID"];
   $sql = "SELECT * FROM event WHERE  Event_Date <=".$today." AND Event_CID=".$cityID." ORDER BY Event_Date ASC LIMIT 20";
i want to separate events based on if it's date is greater than or less than today's date.
when using the greater than sign, like above, i get dates from both sides of the date
when using the less than sign, i get no dates displaying at all.

any ideas of what i could do?
thank you!

Posted: Tue Dec 05, 2006 11:52 am
by feyd
=<

If you insist on using the output from date(), you'll need to place quotes around it in the query for the database to understand that it's a date and not math to perform. Otherwise you can usually use the NOW() function or whatever may be similar in your particular database.

Posted: Tue Dec 05, 2006 12:14 pm
by $var
hmm... using $today = $NOW(); doesn't do anything.
i also tried to look up the function online and came up dry.

how do you use NOW();?

Posted: Tue Dec 05, 2006 2:21 pm
by feyd
With NOW() there would be no variable, it's an SQL function. It returns a properly formatted date-time string for the current time.

Code: Select all

SELECT NOW()
for example.

edit: my brain's on backwards.. the comparison operator is correct using <=.