Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: if statement in where clause
11-27-2012, 06:36 PM #1
- Join Date
- Dec 2010
- Thanked 11 Times in 11 Posts
if statement in where clause
i'm trying to get my code to find exact matches of 'venuename' only when $searchType = 'venue' and $distance = 0.5, otherwise leave out the constraint.
$sql = "
FROM gig AS G, venue AS V, postcodes AS P
WHERE gigdate BETWEEN '$dStart' AND '$dEnd'
AND G.venueid = V.venueid
" . ($searchType == 'venue' && $distance == 0.5 ? 'AND V.venuename = \'$venueName\'' : '' ). "
AND V.venuepostcode = P.postcode
AND G.price <= $searchPrice
for the right syntax to use near 'V.venuename = '$venueName' AND V.venuepostcode = P.postcode AND G.price <=' at line 8
I'm guessing it's something to do with the way i'm escaping the $venueName as it works when I simply input 'AND venuename = '$venueName'. ?
Any help would be very much appreciated, I've been stuck on this for a while.
P.S I've just realised this is actually a PHP question and not an SQL problem, if any mods would like to move it!
Last edited by paddyfields; 11-28-2012 at 05:31 PM.