Jump to content

Dynamically Create Multiple Drop Down Menus


jay83r

Recommended Posts

hey all,

 

i have a tricky problem that i can't get my head around.

 

i have a msql table that will populate a drop down menu, this is fine. I have another table that has a column that contains a number that i want to use to tell how many times the drop down menu should appear.

 

for example.

 

beach house has a drop down number of 8 (8 possible locations to place an option) -

 

so when i display my php page showing this row (using GET) it shows 8 drop down menus from the table drop down menu (all menus are the same) eg.

 

MENU: Window

Sliding Door

Entry Door

 

 

i'm totally lost on how to get the 8 from the beach house row to relate to the number of drop down menus.

without your current code theres nothing specific that can be given to you. a generic example would be along the lines of :

$count = $_GET['numOfMenus'];
$menuList = array();
$sql = "SELECT menuItems FROM menuTable WHERE targetValue = 'Beach House'";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)){
 $menuList[] = $row['menuItems'];
}
for($i=0;$i<=$count;$i++){
 echo "<select name=\"menu{$i}\" id=\"menu{$i}\">"
 foreach($menuList as $menuItem =>$menuValue){
   echo "<option value=\"{$menuValue}\">{$menuValue}</option>";
 }
 echo "</select>";
}

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.