Is it possible to populate a dropdown box from a MySQL dB

Is it possible to populate a dropdown box from a MySQL dB, if so can someone advise me on how to do it.

I know you need to use Ajax make on dropdown box depended on another dropdown box, but i don’t have a clue on how to do either problem.

What I’m trying to do it make on dropdown box depended on another. e.g.

Dropdown box 1 called make
Dropdown box 2 called model

After selecting ford drop the 1st box the second box would populate from the sql with all the ford models.

Can someone send me towards a tutorial or give me some advice on what i need to look up

Thank you

you don’t have to use ajax but it does add that dynamic “flair”, what you can do is
[php]

$query = 'select id, make,model from cars where make = “$make” ';
$result = mysql_query($query);

$dropdown = “”;
while($row = mysql_fetch_row($result))
{
$dropdown .= “$row[2]”;
}
$dropdown .= “”;

echo $dropdown;
[/php]
this assumes $make is retrieved from a tag hard coded into the html
$row[0] is the id of the vehicle in the database and $row[2] is each model this will output a drop down menu with all the available choices

try this for the AJAX pert of it: http://roshanbh.com.np/2007/12/change-dropdown-list-options-values-from-database-with-ajax-and-php.html

Sponsor our Newsletter | Privacy Policy | Terms of Service