PDA

View Full Version : Creating a 2nd drop down list...


pickles
02-25-2008, 01:30 PM
Hello. Another php question from a beginner.

I have a Drop down list that is being populated from a MySQL database. I want to be able to create a 2nd drop down list for certain items in the first drop down list. My first drop down list, lists categories of businesses. If a user selects "Restaurants" I want a second drop down list to appear where the user can choose a cusine if they want. I don't want it to be necessary to select an option from the second list but I want them to be able to. I dod have the first drop down list working. The code follows. I am not sure how to get started on the 2nd list. Any hints, points in the right direction, etc will be appreciated. Thanks!

<?php
$user = "***";
$host = "***";
$password = "***";
$database = "***";

$cxn = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
mysql_select_db($database,$cxn);

$query = "SELECT DISTINCT Category FROM clients ORDER BY Category";
$result = mysql_query($query,$cxn)
or die ("Couldn't execute query.". mysql_error());
/* create form containing selection list */

echo "<form action='processform.php' method='POST'>
<select name='Category'>\n";

while ($row = mysql_fetch_assoc($result))
{
extract($row) ;
echo "<option value='$Category'>$Category\n";
}
echo "</select>\n";
echo "<input type='submit' value='Select Category'>
</form>\n"
?>

twenty1
02-29-2008, 03:59 PM
Maybe this (http://www.websitedatabases.com/database-forum/showpost.php?p=1236&postcount=1) thread will help.