I am having trouble getting search.php to work correctly. I implemented a solution for if the user just searches one term that works great. However, I'm having trouble getting it to work when they search with more than one term (with either a space or , in between words). Here is my code:
$geo = $_GET["geo"];
$broken_up = preg_split("/[\s,]+/", $geo);
end($broken_up);
$last_key = key($broken_up);
reset($broken_up);
// code for if $last_key == 0
else if ($last_key > 0)
{
$geo = implode(" ", $broken_up);
$places = CS50::query("SELECT * FROM places WHERE MATCH (postal_code, place_name, admin_name1,
admin_code1) AGAINST (? IN BOOLEAN MODE)", $geo);
}
If I search, for example, "mary, calif" or "mary,ca", it returns places that have "mary" in their place_name, regardless of the state. In fact, it doesn't return anything from California at all. I've been working on this for quite a while and still can't get it. Any help would be much appreciated!