I have a MySQL table and one of the fields is “category,” the values of which include articles, studies, quotes, etc. For the search form I have checkboxes that correspond with these categories for the user to select which, if not all, to search from.
Right now the following snippet works for searching the entire table indiscriminately (i.e., from rows with “category” including articles, studies, quotes, etc. However, how would I change the following so that if a person selects only “Articles,” the query will return only the rows that have the field “category” with the corresponding value?
$category = $_GET["category"];
$query = "User-submitted query";
$search = mysql_query("SELECT title,body,
MATCH(title, body)
AGAINST('$query' IN BOOLEAN MODE)
AS score FROM resources
WHERE MATCH(title, body) AGAINST ('$query' IN BOOLEAN MODE)");
I tried adding in WHERE category = '$category' ($category in this case would be “Articles”) above but it did not work.
BTW: I am aware of the mysql/mysqli and security user-input issues.
I figured out the problem. The following works: