IF Statement Inside a Query - Stupid Noob Question
Posted: Mon Feb 21, 2011 2:21 pm
In Coldfusion, I can put an "if" statement INSIDE a query. I'm not finding anything in Google showing me a way to do this in PHP though.
Below, I'm feeding URL variables into a query.
Basically, if a specific date isn't defined, then I want all the events for that month/year.
If a specific date IS defined, just the events for that one date.
So, sorta like this:
$getEVENTS = mysql_query( "
SELECT
cal_occurrences.startdate,
cal_occurrences.eid,
cal_events.subject,
cal_events.eventCOLOR
FROM
cal_events
Inner Join cal_occurrences ON cal_occurrences.eid = cal_events.eid
WHERE month(startdate) = $urlMONTH
AND year(startdate) = $urlYEAR
if(isset($_GET["uDAY"])) {
AND day(startdate) = $urlDAY }
" )
or die(mysql_error());
What do I have wrong?
Below, I'm feeding URL variables into a query.
Basically, if a specific date isn't defined, then I want all the events for that month/year.
If a specific date IS defined, just the events for that one date.
So, sorta like this:
$getEVENTS = mysql_query( "
SELECT
cal_occurrences.startdate,
cal_occurrences.eid,
cal_events.subject,
cal_events.eventCOLOR
FROM
cal_events
Inner Join cal_occurrences ON cal_occurrences.eid = cal_events.eid
WHERE month(startdate) = $urlMONTH
AND year(startdate) = $urlYEAR
if(isset($_GET["uDAY"])) {
AND day(startdate) = $urlDAY }
" )
or die(mysql_error());
What do I have wrong?