Jump to content

Select checkbox value does not work in search sql statement


HalRau

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.

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";

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.