View Full Version : How to make dynamic drop boxes

02-22-2010, 02:16 AM

This is sort of a follow up to my last post

I was wondering the best/easiest way to make dynamic drop boxes. Do I need to use Javascript?

Here is some of the code I'm working with. I want select a meal type (breakfast, lunch, dinner, etc.) and then have the subsequent drop box pull up only the relevant meals

$sql_mealtype="SELECT typeID, typeName FROM mealtypes ORDER BY typeID";

while ($row=mysql_fetch_array($result_mealtype))
$type_options.="<OPTION VALUE=\"$typeid\">".$typename;

Meal Type:
<select name="remove_type">
<option><?php echo $type_options?></option>



02-22-2010, 03:53 PM
The only way to do this directly with php, would be to ask for what 'meal' first, then submit the form, handle you're data and write a new select with just the items relating to it.
This is actually how I'd do it anyway, then link AJAX to it to handle it behind the scenes and rewrite the new data. Even though forms that go through box after box just to get the specific related data is horrid looking, at least it will still function without the javascript involved.

So, with the code you have above here, you would use the $typeid provided by you're selection menu to determine what meal type was selected, and query you're 'meals' (maybe?) table where the mealtype is $typeid to populate the next dropdown. That make sense?