SELECT * Statement Question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

SELECT * Statement Question

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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();?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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 <=.
Post Reply