Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.