I am making a search feature that looks for either the location, the category or both. My search for category works, but for the city name I am not getting all the cases.
When the form is filled in, the city field could contain just one city name (ie, Toronto), or it could contain a list of locations (ie, Toronto, Montreal, Vancouver, all of Manitoba). This does not seem to affect which items are displayed, and which ones are left out.
Is there something wrong with my SQL query?
$query = "SELECT id, org_name, prog_name, tollfree, email
FROM organizations";
if ($search_city == '' && $search_cat != '') {
$query .= " WHERE org_type = '$search_cat'";
} else if ($search_city != '' && $search_cat == '') {
$query .= " WHERE geo_area LIKE '%$search_city%'";
} else if ($search_city != '' && $search_cat != '') {
$query .= " WHERE org_type = '$search_cat'
AND geo_area LIKE '%$search_city%'";
}
$query .= " ORDER BY org_name ASC";