I want to make mysqli full text search with or without multiple category based on checkbox selection.
Search is based on four category within same column.
Search category are windows, games, tablet, mobile.
When category/multiple category selected through checkbox selection search should be done for selected category only.
Table Structure
id category title date ...
1 windows windows7 d1 ...
2 games windows games d2 ...
3 tablet windows tablet d3 ...
4 mobile windows mobile d4 ...
5 windows windows8 d5 ...
6 windows windows vista d6 ...
checkboxes for search are
Search in
<li><label><input name="all" type="checkbox" checked="checked" />All</label></li>
<li><label><input name="windows" type="checkbox" />Windows OS</label></li>
<li><label><input name="mobile" type="checkbox" />Windows Mobile</label></li>
<li><label><input name="games" type="checkbox" />Windows Games</label></li>
<li><label><input name="tablet" type="checkbox" />Windows Tablet</label></li>
Example1:
Search for 'windows' should return result as
windows7
windows8
windows vista
When only checkbox windows is checked
Example2:
Search for 'windows' should return result as
windows7
windows8
windows vista
windows games
When checkbox windows and games are checked.
I have made a query but it is not working at all.
$query = "SELECT * FROM $table WHERE ";
$query .= "category='' ";
$query .= "OR category='windows' ";
$query .= "OR category='games' ";
$query .= "OR category='mobile' ";
$query .= "OR category='tablet' ";
$query .= " AND MATCH (title) AGAINST ('+$keyword*' IN BOOLEAN MODE) ORDER by id desc, title desc LIMIT 10";
I have also tried like this but not working.
$query = "SELECT * FROM $table WHERE ";
$query .= "MATCH (category) AGAINST ('' IN BOOLEAN MODE) ";
$query .= "OR MATCH (category) AGAINST ('windows' IN BOOLEAN MODE) ";
$query .= "OR MATCH (category) AGAINST ('games' IN BOOLEAN MODE) ";
$query .= "OR MATCH (category) AGAINST ('mobile' IN BOOLEAN MODE) ";
$query .= "OR MATCH (category) AGAINST ('tablet' IN BOOLEAN MODE) ";
$query .= " AND MATCH (title) AGAINST ('+$keyword*' IN BOOLEAN MODE) ORDER by id desc, title desc LIMIT 10";
Please see why its not working and suggest how search query can be made for no of fields selected.
Thanks.