sonicthehedgehog Posted September 10, 2015 Share Posted September 10, 2015 I'm trying to submit a form is automatically submitted when somebody clicks one of the checkboxes. This part isn't a problem but I'm having a problem with getting the results each time. The form is a series of checkboxes where people can choose to filter results by various options but how do I only get the results if the box is checked? For example if box a is checked and so is box b I want the results to be something like this: $sql_select = "SELECT * "; $sql_from = " FROM stock, product_categories, delivery, options "; $sql_where = " WHERE stock.enabled=1 and stock.deleted=0 and stock.dealer_name= delivery.dealer ";$sql_group = " GROUP BY stock.id";$sql_limit = " LIMIT 500"; if ($boxes_group1<>"") {$sql_where = " AND options.category_1 LIKE %box a% %box b%} $query=$sql_select . $sql_from . $sql_where . $sql_end . $sql_group . $sql_limit; This gives me no results at all even though there are loads of results with box a and also with box b in the category_1 field of the options table. Also there could be around 20 different options so I need to be able to execute the same code every time regardless of which option is selected Link to comment Share on other sites More sharing options...
dsonesuk Posted September 10, 2015 Share Posted September 10, 2015 Surely it should be options.category_1 LIKE '%box a%' OR options.category_1 LIKE '%box b%' Link to comment Share on other sites More sharing options...
davej Posted September 10, 2015 Share Posted September 10, 2015 This looks like a classic 4-way inner join except where are the join constraints? Link to comment Share on other sites More sharing options...
sonicthehedgehog Posted September 10, 2015 Author Share Posted September 10, 2015 Thank you that's more what I'm after, but how do have it so that it only displays it with the 'or' if more than one box is checked and if nothing is checked then that part of the query isn't shown at all? Link to comment Share on other sites More sharing options...
dsonesuk Posted September 10, 2015 Share Posted September 10, 2015 Loop through each checkbox value and concatenate into a single sql statement given a like for each value. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now