project3 Posted January 18, 2008 Share Posted January 18, 2008 Hi, What I need to do is have like 25 identical drop down boxes besides the name of the box. I know how to fill it from the database. but only if i do 25 mysql statements. so what i would like to do is fill the <options></options> values only once. Then I want to use that data inbetween the select boxes with different names. is there a way to do that or do i need to have multiple sql statements. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/86568-solved-multipe-dynamic-select-box/ Share on other sites More sharing options...
priti Posted January 18, 2008 Share Posted January 18, 2008 Can you explain with dummy example what you are trying to achieve? Regards Quote Link to comment https://forums.phpfreaks.com/topic/86568-solved-multipe-dynamic-select-box/#findComment-442447 Share on other sites More sharing options...
timmah1 Posted January 18, 2008 Share Posted January 18, 2008 I'm assuming this is kinda like what eBay does when you post a new listing, pick one category and the sub-categories show up next to it, but he wants it in a drop down menu instead. Look into using AJAX, that will help Quote Link to comment https://forums.phpfreaks.com/topic/86568-solved-multipe-dynamic-select-box/#findComment-442451 Share on other sites More sharing options...
Psycho Posted January 18, 2008 Share Posted January 18, 2008 The OP stated he wanted 25 identical slect boxes. This is very simple, just create the select options once - but instead of echo'ing them to the page, add them to a variable. Then you can add the options to as many select lists as you want. Also, if you need to pre-select the default option for each independantly, then just create a function using the result set from the query: <?php $query = "SELECT label, value FROM table"; $results = mysql_query($query); while ($option = mysql_fetch_assoc($results)) { $optionList .= "<option value = \"{$option['value']}\">{$option['label']}</option>\n"; } echo "<select name=\"option1\">$optionList</select>"; echo "<select name=\"option2\">$optionList</select>"; echo "<select name=\"option3\">$optionList</select>"; . . . ?> Quote Link to comment https://forums.phpfreaks.com/topic/86568-solved-multipe-dynamic-select-box/#findComment-442552 Share on other sites More sharing options...
project3 Posted January 18, 2008 Author Share Posted January 18, 2008 I believe this will help me out. $optionList .= and then i can pull that up every where i want that drop down. Thanks mjdamato Quote Link to comment https://forums.phpfreaks.com/topic/86568-solved-multipe-dynamic-select-box/#findComment-442903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.