calmchess Posted June 28, 2010 Share Posted June 28, 2010 how do i code a dropdown box with php so that i can add as many fields as i like without modifying the html? i envision an array in ad database being brought out exploded and the resulting array is used to populate the dropdown. coding all the database stuff isn't necessary if you can just show me how to populate the dropdown box with an array. Link to comment https://forums.phpfreaks.com/topic/206110-dynamic-dropdown/ Share on other sites More sharing options...
kickstart Posted June 28, 2010 Share Posted June 28, 2010 Hi Assuming you do not need a seperate specified value:- $SomeArray = array('London','Paris','Rome'); $OutDropDown = "<select name='DropDownName'><option>".implode("</option><option>",$SomeArray)."</option></select>"; If you want a way to do it with a value matching an ID then not sure of a way to do it in a single line $SomeArray = array(1=>'London',2=>'Paris',4=>'Rome'); $OutDropDown = "<select name='DropDownName'>"; foreach($SomeArray AS $SomeId=>$SomeName) { $OutDropDown .= "<option value='$SomeId'>$SomeName</option>"; } $OutDropDown .= "</select>"; All the best Keith Link to comment https://forums.phpfreaks.com/topic/206110-dynamic-dropdown/#findComment-1078417 Share on other sites More sharing options...
calmchess Posted June 28, 2010 Author Share Posted June 28, 2010 thanks the second example worked for me........i never would have figured that out Link to comment https://forums.phpfreaks.com/topic/206110-dynamic-dropdown/#findComment-1078432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.