PHP & Mysql help needed to populate drop down list

Soldato
Joined
15 Feb 2003
Posts
10,125
Location
Europe
Can anyone tell me how I'd go about populating a drop down list from a mysql database using php?

I have a database called "test" in it I have two tables, one called "manufacturers"

It contains "manufacturer_id", and "manufacturer_name")

The other table is called "models"

This contains "manufacturer_id", "model_id", and "model_name"

My goal is to have a dropdown list where a person selects a manufacture, and then a second drop down where they can select a model made by that manufacturer.

Finally when using selecting the model from the second drop down, they should be directed to a model specific web page.

I can connect to the database and close the database, but none of guides i've tried to follow for the actual function work for me, with my limited knowledge.

Can anyone of you guys help?
 
to generate the first box, I would do:


Code:
echo "<select>";

$result = mysql_query("SELECT * FROM manufacturers");

while($row = mysql_fetch_array($result))
  {
  echo "<option value=". $row["manufacturer_id"] .">". $row["manufacturer_name"] . "</option>";
  }
echo "</select>";
?>
Then for the other box, you'll need to do some javascripty ajaxy thing that I don't have time to think about at the moment i'm afraid!
 
Back
Top Bottom