Jump to content

Select checkbox value does not work in search sql statement


Go to solution Solved by cyberRobot,

Recommended Posts

Hi,

I have this code for searching records in a MYSQL database. I would like to filter the results based on the value of the checkbox field "LiveOnWeb which equals 1. For some reason it is not filtering the results. All records matching the "LIKE" conditions show in the results.

Here is the select statement:

"SELECT * FROM members WHERE LiveOnWeb = 1 AND
  BusinessName LIKE '%{$searchTermDB}%'
      OR BusinessDescription LIKE '%{$searchTermDB}%'
      OR SearchKeyWords LIKE '%{$searchTermDB}%'
      ORDER BY BusinessName";

 

The statement "WHERE LiveOnWeb = 1" works on other pages but not here. Any ideas?

Thanks for your help.

  • Solution

Try adding parenthesis around the conditions using "OR":

 

 

"SELECT * FROM members WHERE LiveOnWeb = 1 AND
  (BusinessName LIKE '%{$searchTermDB}%'
      OR BusinessDescription LIKE '%{$searchTermDB}%'
      OR SearchKeyWords LIKE '%{$searchTermDB}%')
      ORDER BY BusinessName";
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.