Jump to content

Search results are iffy


devknob

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/76158-search-results-are-iffy/
Share on other sites

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 

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.