Jump to content

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"

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.