HalRau Posted October 2, 2013 Share Posted October 2, 2013 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. Link to comment https://forums.phpfreaks.com/topic/282640-select-checkbox-value-does-not-work-in-search-sql-statement/ Share on other sites More sharing options...
cyberRobot Posted October 2, 2013 Share Posted October 2, 2013 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"; Link to comment https://forums.phpfreaks.com/topic/282640-select-checkbox-value-does-not-work-in-search-sql-statement/#findComment-1452194 Share on other sites More sharing options...
HalRau Posted October 2, 2013 Author Share Posted October 2, 2013 That fixed it! Thank you cyberRobot Link to comment https://forums.phpfreaks.com/topic/282640-select-checkbox-value-does-not-work-in-search-sql-statement/#findComment-1452288 Share on other sites More sharing options...
cyberRobot Posted October 2, 2013 Share Posted October 2, 2013 I have marked the topic as solved. If you need anything else, please mark it as unsolved...or start a new topic. Link to comment https://forums.phpfreaks.com/topic/282640-select-checkbox-value-does-not-work-in-search-sql-statement/#findComment-1452298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.