Jump to content

Why is one condition being omitted ?


iPixel

Recommended Posts

Here's my SQL query

 

"SELECT * FROM syx_ad WHERE firstname LIKE '%$q%' OR lastname LIKE '%$q%' AND status = 'Active' LIMIT 20"

 

the LIKE's are satisfied but it doesnt bother checking for status.. results still display the user if his/hers status is Inactive... am i just doing something wrong?

Link to comment
https://forums.phpfreaks.com/topic/155554-why-is-one-condition-being-omitted/
Share on other sites

Hi

 

Do you want:-

 

"SELECT * FROM syx_ad WHERE firstname LIKE '%$q%' OR (lastname LIKE '%$q%' AND status = 'Active') LIMIT 20"

 

or

 

"SELECT * FROM syx_ad WHERE (firstname LIKE '%$q%' OR lastname LIKE '%$q%') AND status = 'Active' LIMIT 20"

 

Default precedence it will do the AND first. However it is best to use brackets to make the logic more obvious when you next have to touch the code.

 

All the best

 

Keith

Here's the logic to what i want.

 

Basically the search has to be %LIKE% either firstname or last name, that doesnt matter.. just status HAS TO BE ACTIVE

 

"SELECT * FROM syx_ad WHERE status = '$stat' AND firstname LIKE '%$q%' OR status = '$stat' AND lastname LIKE '%$q%' AND status = '$stat' LIMIT 20"

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.