devknob Posted November 6, 2007 Share Posted November 6, 2007 Anyone see a reason this wouldnt work? SELECT * FROM 'listings' WHERE 'siteaddy' LIKE '%siteaddy%' OR 'ccontact' LIKE '%name%' OR 'ccompany' LIKE '%cname%' OR 'tenant' LIKE '%tenant%' OR 'sitestate' LIKE '%st%' OR 'propertytype' LIKE '%type%' OR 'askingprice' BETWEEN '0' && '10' OR 'caprate' BETWEEN '0' && '10' OR 'cashoncash' BETWEEN '0' && '10' ORDER BY id DESC LIMIT 0 , 30 Quote Link to comment Share on other sites More sharing options...
Rhysyngsun Posted November 6, 2007 Share Posted November 6, 2007 Two things to change: 'listings' to either listings or `listings` and then change your &&'s to AND full code: SELECT * FROM listings WHERE 'siteaddy' LIKE '%siteaddy%' OR 'ccontact' LIKE '%name%' OR 'ccompany' LIKE '%cname%' OR 'tenant' LIKE '%tenant%' OR 'sitestate' LIKE '%st%' OR 'propertytype' LIKE '%type%' OR 'askingprice' BETWEEN '0' AND '10' OR 'caprate' BETWEEN '0' AND '10' OR 'cashoncash' BETWEEN '0' AND '10' ORDER BY id DESC LIMIT 0 , 30 Quote Link to comment Share on other sites More sharing options...
fenway Posted November 6, 2007 Share Posted November 6, 2007 I'd put parenthesis around your BETWEEN clauses... ANDs and ORs don't mix. Quote Link to comment Share on other sites More sharing options...
devknob Posted November 6, 2007 Author Share Posted November 6, 2007 Im using this query to take search for items in our db mysql_query("SELECT * FROM listings WHERE siteaddy LIKE '%$siteaddy%' AND ccontact LIKE '%$name%' AND ccompany LIKE '%$cname%' AND tenant LIKE '%$tenant%' AND sitestate LIKE '%$st%' AND propertytype LIKE '%$type%' OR (askingprice BETWEEN '$prf' AND '$prt') OR (caprate BETWEEN '$capf' AND '$capt') OR (cashoncash BETWEEN '$cocf' AND '$coct') ORDER BY lid DESC LIMIT 0 , 30"); and if $st = CA, and nothing else is set, it will still return items in states other than CA. What am I missing? Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 i think the problem is that u use AND you have tons of and so i guess it only satisfy your the state but not the other ( and ) Quote Link to comment Share on other sites More sharing options...
fenway Posted November 7, 2007 Share Posted November 7, 2007 No need to double-post; I've merged these topics... and if $st = CA, and nothing else is set, it will still return items in states other than CA. What am I missing? That's because if you where to echo your query (which you didn't) you'd see field LIKE '%%' which matches everything. You'll have to build the where clause dynamically. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.