Some help with arrays / displaying results
I have one page that has a drop down menu, once the user selects the desired option it will then pass the selected value to a 2nd drop down. Once they select there next option I pass that value...
Now I would like to hold the 2nd selected value have it search the database find all that match the selected and then only display what matches it in the corresponding ROWS in the database.
I was hoping to get some help with an array because I would like it, to display the infromation found in a format of an address for example
Company Name
Address
City, State Zip Code
Phone Number
Website
The user is selecting there "STATE" Once selected it pass that value to "getCity" Then displays a list of "City's" in the selected "STATE"
So once they select "CITY" id like it to display all Companys found in that "CITY" in the format I listed above
PHP Code:
// =====================================================================================================
// Construct parts overview after user selected state, city.
// =====================================================================================================
if( (isset($_GET['getpart']) AND isset($_GET['state']) AND isset($_GET['city']))
OR (isset($_GET['search']) ) ) {
if(isset($_GET['getpart'])) {
$st = $_GET['state'];
$ci = $_GET['city'];
$query="SELECT dealerlocater.state, ".
" dealerlocater.company, dealerlocater.address, dealerlocater.city, dealerlocater.stateabb, dealerlocater.zip, dealerlocater.phone, dealerlocater.web ".
" FROM dealerlocater ".
" WHERE state='$st' ".
" GROUP BY dealerlocater.state ".
" ORDER BY dealerlocater.state ";
}
$res = mysql_query($query)
or die("Invalid query: " . mysql_query());
// verify that the part number has been passed
if (!isset($_REQUEST['city']) OR strlen(trim(strip_tags($_REQUEST['city']))) < 4 )
die("Invalid city specified.");
// sanitize and save the requested part number
$city = trim(strip_tags($_REQUEST['city']));
// select the data row for the specified part number
$res = mysql_query("SELECT * FROM dealerlocater WHERE city='$city' LIMIT 1")
or die("Invalid select query: " . mysql_query());
// verify that a row has been selected, if not: issue message
if (mysql_num_rows($res) < 1)
echo "No database information for '$city' found.";
// a row had been selected, process the data
else {
$row = mysql_fetch_assoc($res);
$city = $row['city'];
$st = $row['state'];
echo $city;
?>
Re: Some help with arrays / displaying results
I would rewrite the echoing part to something like this.
PHP Code:
if (mysql_num_rows($res) > 0){
while ($row=mysql_fetch_assoc($res){
echo $row['city'].'<br/>';
echo $row['name'].'<br/>';
//whatever fields that you want to display
}
}