Hi,
I`m using the following code to build a search form which searches a database table for specific items.
<?php
if(isset($_POST['Submit']))
{
$club_name = mysql_real_escape_string($_POST['club_name']);
$town = mysql_real_escape_string($_POST['town']);
$county = mysql_real_escape_string($_POST['county']);
$postcode = mysql_real_escape_string($_POST['postcode']);
$price_low = mysql_real_escape_string($_POST['price_low']);
$price_high = mysql_real_escape_string($_POST['price_high']);
$disabled = mysql_real_escape_string($_POST['disabled']);
$carp = mysql_real_escape_string($_POST['carp']);
$night_fishing = mysql_real_escape_string($_POST['night_fishing']);
$closed_season = mysql_real_escape_string($_POST['closed_season']);
$opm = mysql_real_escape_string($_POST['opm']);
if($club_name){ $whereParts[] = "club_name LIKE '%$club_name%'"; }
if($town){ $whereParts[] = "town LIKE '%$town%'"; }
if($county){ $whereParts[] = "county = '%$county%'"; }
if($postcode){ $whereParts[] = "postcode LIKE '%$postcode%'"; }
if($price_low){ $whereParts[] = "price_low LIKE '%$price_low%'"; }
if($price_high){ $whereParts[] = "price_high LIKE '%$price_high%'"; }
if($disabled){ $whereParts[] = "disabled_access = '%$disabled%'"; }
if($carp){ $whereParts[] = "carp_syndicate = '%$carp%'"; }
if($night_fishing){ $whereParts[] = "night_fishing_allowed = '%$night_fishing%'"; }
if($closed_season){ $whereParts[] = "close_season = '%$closed_season%'"; }
if($opm){ $whereParts[] = "open_membership = '%$opm%'"; }
$whereClause = implode(' AND ', $whereParts);
$sql = "SELECT * FROM fisheries WHERE " . $whereClause;
// Mysql query is to be put here
// Results here
//show_header($title = "Search Angling Clubs » Results");
echo "Clubs Results";
echo "<br />";
echo $sql;
//show_footer();
exit();
}
else
{
//show_header($title = "Search Angling Clubs");
echo "<form id=\"clubs_search\" name=\"clubs_search\" method=\"post\" action=\"search.php?p=clubs\">
<table width=\"100%\" border=\"0\">
<tr>
<td colspan=\"2\" class=\"tablec\"><div align=\"center\">
<h3>Search Angling Clubs</h3>
</div></td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Club Name </td>
<td width=\"50%\" class=\"tablec\"><input name=\"club_name\" type=\"text\" id=\"club_name\" /></td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Town</td>
<td width=\"50%\" class=\"tablec\"><input name=\"town\" type=\"text\" id=\"town\" /></td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">County</td>
<td width=\"50%\" class=\"tablec\"><select name=\"county\" class=\"textfield\">
<option value=\"1\" selected=\"selected\">Avon</option>
<option value=\"2\">Bedfordshire</option>
<option value=\"3\">Berkshire</option>
<option value=\"4\">Buckinghamshire</option>
<option value=\"5\">Cambridgeshire</option>
<option value=\"6\">Cheshire</option>
<option value=\"7\">Cleveland</option>
<option value=\"8\">Cornwall</option>
<option value=\"9\">Cumbria</option>
<option value=\"10\">Derbyshire</option>
<option value=\"11\">Devon</option>
<option value=\"12\">Dorset</option>
<option value=\"13\">Durham</option>
<option value=\"14\">East Sussex</option>
<option value=\"15\">Essex</option>
<option value=\"16\">Gloucestershire</option>
<option value=\"17\">Gt London</option>
<option value=\"18\">Gt Manchester</option>
<option value=\"19\">Hampshire</option>
<option value=\"20\">Hereford and Worcester</option>
<option value=\"21\">Hertfordshire</option>
<option value=\"22\">Humberside</option>
<option value=\"23\">Kent</option>
<option value=\"24\">Lancashire</option>
<option value=\"25\">Leicestershire</option>
<option value=\"26\">Lincolnshire</option>
<option value=\"27\">Merseyside</option>
<option value=\"28\">Norfolk</option>
<option value=\"29\">Northamptonshire</option>
<option value=\"30\">Northumberland</option>
<option value=\"31\">Nottinghamshire</option>
<option value=\"32\">Oxfordshire</option>
<option value=\"33\">Scotland</option>
<option value=\"34\">Shropshire</option>
<option value=\"35\">Somerset</option>
<option value=\"36\">Staffordshire</option>
<option value=\"37\">Suffolk</option>
<option value=\"38\">Surrey</option>
<option value=\"39\">Tyne and wear</option>
<option value=\"40\">Wales</option>
<option value=\"41\">Warwickshire</option>
<option value=\"42\">West Sussex</option>
<option value=\"43\">Wiltshire</option>
<option value=\"44\">Yorkshire</option>
</select> </td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Postcode</td>
<td width=\"50%\" class=\"tablec\"><input name=\"postcode\" type=\"text\" id=\"postcode\" /></td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Price (low > high) </td>
<td width=\"50%\" class=\"tablec\">£
<input name=\"price_low\" type=\"text\" value=\"0.00\" size=\"8\" maxlength=\"6\" />
To £
<input name=\"price_high\" type=\"text\" value=\"0.00\" size=\"8\" maxlength=\"6\" /></td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Disabled Access</td>
<td width=\"50%\" class=\"tablec\"><input name=\"disabled\" type=\"radio\" value=\"1\" />
Yes
<input name=\"disabled\" type=\"radio\" value=\"0\" />
No</td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Carp Syndicate </td>
<td width=\"50%\" class=\"tablec\"><input name=\"carp\" type=\"radio\" value=\"1\" />
Yes
<input name=\"carp\" type=\"radio\" value=\"0\" />
No</td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Night Fishing Allowed </td>
<td width=\"50%\" class=\"tablec\"><input name=\"night_fishing\" type=\"radio\" value=\"1\" />
Yes
<input name=\"night_fishing\" type=\"radio\" value=\"0\" />
No</td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Enforced Closed Season </td>
<td width=\"50%\" class=\"tablec\"><input name=\"closed_season\" type=\"radio\" value=\"1\" />
Yes
<input name=\"closed_season\" type=\"radio\" value=\"0\" />
No</td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Open For Membership </td>
<td width=\"50%\" class=\"tablec\"><input name=\"opm\" type=\"radio\" value=\"1\" />
Yes
<input name=\"opm\" type=\"radio\" value=\"0\" />
No</td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Species Available </td>
<td width=\"50%\" class=\"tablec\">
<select name=\"species[]\" size=\"5\" multiple=\"multiple\">
<option value=\"1\">Barbel</option>
<option value=\"2\">Bleak</option>
<option value=\"3\">Bream</option>
<option value=\"4\">Carp</option>
<option value=\"5\">Carp (Crucian)</option>
<option value=\"6\">Carp (Grass)</option>
<option value=\"7\">Catfish</option>
<option value=\"8\">Chub</option>
<option value=\"9\">Dace</option>
<option value=\"10\">Eel</option>
<option value=\"11\">Grayling</option>
<option value=\"12\">Gudgeon</option>
<option value=\"13\">Minnow</option>
<option value=\"14\">Orfe</option>
<option value=\"15\">Perch</option>
<option value=\"16\">Pike</option>
<option value=\"17\">Roach</option>
<option value=\"18\">Rudd</option>
<option value=\"19\">Salmon</option>
<option value=\"20\">Sturgeon</option>
<option value=\"21\">Tench</option>
<option value=\"22\">Trout</option>
<option value=\"23\">Trout (Blue)</option>
<option value=\"24\">Trout (Brook)</option>
<option value=\"25\">Trout (Brown)</option>
<option value=\"26\">Trout (Rainbow)</option>
<option value=\"27\">Trout (Tiger)</option>
<option value=\"28\">Zander</option>
</select>
</td>
</tr>
<tr>
<td width=\"50%\" class=\"tablec\">Image Verification</td>
<td width=\"50%\" class=\"tablec\"><img src=\"visual.php\" width=\"200\" height=\"60\" alt=\"Visual CAPTCHA\" /><br />
(Copy the code from the image above into the box below)<br />
<input name=\"usercode\" type=\"text\" id=\"usercode\" /></td>
</tr>
<tr>
<td colspan=\"2\" class=\"tablec\"><div align=\"center\">
<input type=\"reset\" name=\"Reset\" value=\"Reset Form\" /> <input type=\"Submit\" name=\"Submit\" value=\"Start Search\" />
</div></td>
</tr>
</table>
</form>";
//show_footer();
}
?>
Now, the SQL query builds properly and out puts into the browser correctly, but what I want to do is add to that query the selected items from the <select name=\"species[]\" size=\"5\" multiple=\"multiple\"> list.
I understand that it goes into an array as defined by species[], but the problem I am having is how to collect the information from the array and build it into the query.
I`ve searched google without luck, so can somebody help me here please?