need help dynamic drop down

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
l_starter_l
Forum Newbie
Posts: 1
Joined: Fri Dec 05, 2008 6:27 pm

need help dynamic drop down

Post by l_starter_l »

When posting PHP code in this forum, please enclose it in [ php] .. tags for easier reading, as I have done below for you. Thank you.

I need help to create a dynamic drop down menu from a database
This is where I select the manufacturer of a car and the the corresponding
models load in the second list.

I wrote this code but it doesnt seem to work and anyone correct it for me

Code: Select all

 
<?php 
$conn=odbc_connect("cisproject","" ,"");// database connection
 
$make = $_POST['manuf_name'];
 
 
if ($make){
/////////////////////////////////////////////////
$query = sprintf("SELECT * FROM Models where manufacture_id='$make'");
$result = @mysql_query($query); 
$rowModel = mysql_fetch_array($result);
/////////////////////////////////////////////////
}
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<body>
 
<form id="form1" name="form1" method="post" action="drop.php" >
 
<select name="make" onChange="document.forms[0].submit()">
<option value="">Select Make</option>
<option value="1" <?php if(!(strcmp(1, $make))){echo "selected";}?>>LEXUS</option>
<option value="2" <?php if(!(strcmp(2, $make))){echo "selected";}?>>TOYOTA</option>
 
</select>
 
 
<select name="model">
<option value="">Select Model</option>
<?php do { ?>
<option value="<?php echo $rowModel['manufactures_id']; ?>"><?php echo $rowModel['model_name']; ?></option>
<?php }while ($rowModel = mysql_fetch_array($result)); ?>
</select>
 
</form>
 
</body>
</html>
 
Can someone review it and see whats wrong
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: need help dynamic drop down

Post by josh »

l_starter_l wrote:I wrote this code but it doesnt seem to work and anyone correct it for me
Not without more information
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: need help dynamic drop down

Post by califdon »

You need to tell us two things:
  1. What you want your code to do
  2. What your code is doing now
Without knowing that, we can't help you.
Post Reply