Jump to content

[SOLVED] using LIKE '' OR LIKE ''


severndigital

Recommended Posts

i have a query that's not working perfectly.

SELECT *
FROM prod_list
WHERE
access_levels LIKE '%$user_level%' 
AND name LIKE '%$search%'
OR short_desc LIKE '%$search%'
OR description LIKE '%$search%'
AND active = '1'

 

what happens is, if short_desc or description or name match, it returns results reguardless of the access_level or the active

 

I believe it's the use of OR, but i'm not sure how to produce the correct results without using OR.

 

Any ideas would be great.

 

Thanks,

C

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/134258-solved-using-like-or-like/
Share on other sites

AND is multiplication

OR is addition

 

You must use () to get proper order of conditions

 

SELECT *
FROM prod_list
WHERE
access_levels LIKE '%$user_level%'
AND (name LIKE '%$search%'
OR short_desc LIKE '%$search%'
OR description LIKE '%$search%')
AND active = '1'

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.