I decided to test it on a multiple select field with fewer options than the state_province one. So I'm doing this with horse gender.
search_form
PHP Code:
<select name="horse_sex[]" style="width:180px;" multiple size="4">
<option value="">-- Any Sex --</option>
<option value="Gelding">Gelding</option>
<option value="Mare">Mare</option>
<option value="Stallion">Stallion</option>
</select>
search_results
PHP Code:
$sex = $_GET['horse_sex[]'];
$sexes = array('Gelding', 'Mare', 'Stallion');
if(strlen($sex) > 0){
if($state1 OR $state2 OR $state3 OR $state4) $sql .= " AND";
foreach($sexes as $sex)
{
$sql .= " horse_sex = '$sex' OR";
}
$sql .= rtrim($sql, "OR");
$state5 = true;
}
Searching for one selected item works fine. When I select two items, it returns search results only for the item in the bottom of the selected list. For example, if I want to search for mares and stallions and select those two, it only returns results for stallions. So something isn't working right in the foreach loop.
What do you think?
Bookmarks