Jump to content

dynamic drop down menu mysql db


jackson4

Recommended Posts

hello,

 

i have created a script where the php connects to the database, selects the table, and inserts the the data from the table into a drop down menu.  if the user selects one of the options in the drop down box, i would like the php to connect to another table in the database, perform a select query, and populate another drop down menu with those results.  i have had trouble completing this second task and would appreciate any help.  here is the code, the comment at end describes what i need:

<?php

include 'opendb.php';
?>

<html> 

<body>
<form id="form1" name="form1" method="get" action="<?php echo $PHP_SELF; ?> ">
Choose your Option :<br>
<select name="select">
<option value="">-- Select --</option>

<?php

$query="SELECT * FROM db_table";
$list=mysql_query("select * from db_table");

while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<?php echo $row_list ?>" <?php if($row_list['id']==$select){ echo "selected"; } ?>><?php echo $row_list['name']; ?></option>
<?php

}
?>
<input type="submit" name="Submit" value="Select" >
</form>
</select>

/*after user selects option from db_table, i would like to connect to another table in the database and create a drop down menu with the results from the second table. */

Link to comment
https://forums.phpfreaks.com/topic/110632-dynamic-drop-down-menu-mysql-db/
Share on other sites

that looks to me like you would have to use javascript and ajax i don't know how to do it but you could do some research but i have used the xajax class before works great if you don't want to write any javascript :)

here is the link http://xajaxproject.org/

 

Scott.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.