Hi,
I have a page where a user can search for suppliers in a given county (selected from a list).
I had everything working until I saw that the results set was returning the value of the county and not the name (when a supplier signs up they post their county and it gets sent to the database as a value).
So what I have done is get the results to return the name of the supplier liek:
You searched for "county" here are the results,
or,
Your search for "county" returned no results.
The problem is that now it is not returning any search results, it mearly says "no results found" when I know there are records in the database:
<html>
<title><?php print $title ?></title>
<form name="form" action="<?=$_SERVER["PHP_SELF"]?>" method="get">
<p>County:
<name="county">
<?php
//$currentvalue0=$row['county'];
$counties = array(1=>'Aberdeenshire', 'Anglesey', 'Angus', 'Argyll', 'Avon', 'Ayrshire', 'Banffshire', 'Bedfordshire', 'Berkshire', 'Berwickshire', 'Borders', 'Buckinghamshire', 'Bute', 'Caithness', 'Cambridgeshire', 'Central Scotland', 'Cheshire', 'Clackmananshire', 'Cleveland', 'Clwyd', 'Cornwall', 'County Antrim', 'County Down', 'County Durham', 'County Fermanagh', 'County Londonderry', 'County Tyrone', 'Cumbria', 'Denbighshire', 'Derbyshire', 'Devon', 'Dorset', 'Dumfries and Galloway', 'Dunbartonshire', 'Durham', 'Dyfed', 'East Ayrshire', 'East Lothian', 'East Sussex', 'East Yorkshire', 'Edinburgh', 'Essex', 'Fife', 'Glamorgan', 'Gloucestershire', 'Grampian', 'Greater London', 'Greater Manchester', 'Guernsey', 'Gwent', 'Gwynedd', 'Hampshire', 'Herefordshire', 'Hertfordshire', 'Highlands and Islands', 'Humberside', 'Inverness-shire', 'Isle of Arran', 'Isle of Man', 'Isle of Skye', 'Isle of Wight', 'Jersey', 'Kent', 'Lanarkshire', 'Lancashire', 'Leicestershire', 'Lincolnshire', 'Lochaber', 'London', 'Londonderry', 'Lothian', 'Merseyside', 'Middlesex', 'Moray', 'Nottinghamshire', 'Orkneys', 'Outer Hebrides', 'Oxfordshire', 'Peeblesshire', 'Perthshire', 'Powys', 'Shropshire', 'Somerset', 'South Yorkshire', 'Staffordshire', 'Stirlingshire', 'Strathclyde', 'Suffolk', 'Surrey', 'Sutherland', 'Swansea', 'Tayside', 'Tyne and Wear', 'Warwickshire', 'West Lothian', 'West Midlands', 'West Sussex', 'West Yorkshire', 'Wester Ross', 'Wiltshire', 'Worcestershire');
echo '<select name="county"><option value="01" />Please Select a County';
/*for ($i=1; $i <= sizeof($counties); $i++)
{ */
foreach($counties as $_key => $_county)
{
echo '<option value="'.sprintf("%03d",$_key).'"selected />'.$_county.'</option>';
/*echo '<option value="'.($_key < 0 ? '0'.$_key : $_key).'" selected />'.$_county.'</option>';*/
}
//}
/* $lz = strlen($i) == 1 ? '0'.$i : $i;
echo '<option value="'.$lz.'" selected />'.$counties[$i-1];
}
echo '</select>'; */
?>
</p>
<input type="submit" name="Submit" value="Search" />
</form>
<html>
<?php
$var = /*@$_GET['county']*/$counties[$_GET['county']] ;
$county = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($county == "")
{
echo "<p>Please enter a search...</p>";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "<p>Please enter a search</p>";
exit;
}
/*$query = "select county, area_covered1, area_covered2, area_covered3, supplierid, username from suppliers where county =\"$county\" order by username"; */
$query = "select county
, area_covered1
, area_covered2
, area_covered3
, supplierid
, username
from suppliers
where '$county' in
( county
, area_covered1
, area_covered2
, area_covered3 )
order
by username";
$numresults=mysql_query($query) or die(mysql_error());
$numrows=mysql_num_rows($numresults);
if ($numrows == 0)
{
echo "<h4>Results</h4>";
echo "<p>Sorry, your search: "" . $counties[$_GET['county']] . "" returned zero results</p>";
}
It seems that maybe this bit is causing the offence as it could be that it is selecting all counties...:
foreach($counties as $key => $county)
{
echo '<option value="'.sprintf("%03d",$key).'"selected />'.$county.'</option>';
Please help with any suggestions as to how I can make this work.
Thanks,
G