Hi,
Hi,
When my users register they fill out the county they live in. They can then go and search for suppliers in that county, or (for flexibility) search on other counties. The problem I have is that I can get my drop down to display the county that the user lives in but then I need to search for suppliers against that who are obviously in a different table. It is the code that searches for the supplier that is not working (no errors).
My code look slike so:
$id = $_SESSION['username'];
$query1 = "select * from users where username='$id'";
//now we pass the query to the database
$result1=mysql_query($query1) or die("Could not get data.".mysql_error());
//get the first (and only) row from the result
$row = mysql_fetch_array($result1, MYSQL_ASSOC);
$county=$row['county'];
?>
<html>
<form name="form" action="suppliersearch.php" method="get">
<p>County:
<name="q" </td><td>
<?php
$currentvalue0=$row['county'];
$counties = array('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" />Aberdeenshire';
for ($i=1; $i <= sizeof($counties); $i++)
{
//adds a leading zero if needed
$lz = strlen($i) == 1 ? '0'.$i : $i;
$checkedStatus = '';
if ($i == $currentvalue0)
{
$checkedStatus = 'SELECTED';
}
echo '<option value="'.$lz.'" '.$checkedStatus.'>'.$counties[$i-1];
}
echo '</select>';
?>
</p>
<input type="submit" name="Submit" value="Search" />
</form>
<html>
So far we have displayed the county that the user selected, now I need to search on the suppliers from this:
$query = "select county, supplierid, username from suppliers where county = '$county' order by username"; // EDIT HERE and specify your table and field names for the SQL query
$numresults=mysql_query($query) or die(mysql_error());
$numrows=mysql_num_rows($numresults);
/*$query = "select county, supplierid, username from suppliers where county = "$county";
order by username"; // EDIT HERE and specify your table and field names for the SQL query
$numresults=mysql_query($query) or die(mysql_error());
$numrows=mysql_num_rows($numresults);
$row = mysql_fetch_array($numresults, MYSQL_ASSOC);*/
print("Welcome to the supplier search page <b>".$_SESSION["username"]."</b><br>");
print("<a href=\"logout.php?".session_name()."=".session_id()."\">Logout</a>");
// Get the search variable from URL
$var = @$_GET['q'] ;
$county = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=10;
Any ideas?
Thanks