Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-27-2012, 05:36 PM   PM User | #1
paddyfields
Regular Coder

 
Join Date: Dec 2010
Location: London
Posts: 278
Thanks: 60
Thanked 11 Times in 11 Posts
paddyfields is an unknown quantity at this point
Question if statement in where clause

Hello.

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.

code snippet
PHP Code:
$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
HAVING distance<=$distance

"

The error I'm getting is this...
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.

Many thanks
Patrick.

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 04:31 PM..
paddyfields is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:27 AM.


Advertisement
Log in to turn off these ads.