oceans Posted May 2, 2007 Share Posted May 2, 2007 Dynamically create List value entries. Please advice me on how to create list box entries at run time Say: $var1=1; $var2=2; My list box is empty right now <select name="Combo1" id="Combo1"> </select> Quote Link to comment https://forums.phpfreaks.com/topic/49594-solved-dynamically-create-list-value-entries/ Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Are the entries coming from a db or where? If so, your last post (the one I helped you with) should be a clear enough example. Quote Link to comment https://forums.phpfreaks.com/topic/49594-solved-dynamically-create-list-value-entries/#findComment-243171 Share on other sites More sharing options...
oceans Posted May 2, 2007 Author Share Posted May 2, 2007 Thrope, I understood your example, this time I want to populate list box, I agree the data comes after quary, just to modularise i am putting as variable in this example. please advice, thaks. Quote Link to comment https://forums.phpfreaks.com/topic/49594-solved-dynamically-create-list-value-entries/#findComment-243172 Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Sorry, I'm not sure I follow your last post. I'll just show you an example using an array and a foreach loop. <?php $vals = array('foo','boo','bar'); echo "<select name=\"Combo1\" id=\"Combo1\">"; foreach ($vals as $v) { echo " <option value=\"$v\">$v</option>"; } echo "</select>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/49594-solved-dynamically-create-list-value-entries/#findComment-243175 Share on other sites More sharing options...
oceans Posted May 2, 2007 Author Share Posted May 2, 2007 Thanks, it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/49594-solved-dynamically-create-list-value-entries/#findComment-243177 Share on other sites More sharing options...
oceans Posted May 2, 2007 Author Share Posted May 2, 2007 can any one halp me how can I insert result variable from quary in echo " <option value=\"$v\">$v</option>"; I have to change "$v", but somthing is hitting there Quote Link to comment https://forums.phpfreaks.com/topic/49594-solved-dynamically-create-list-value-entries/#findComment-243235 Share on other sites More sharing options...
oceans Posted May 2, 2007 Author Share Posted May 2, 2007 thanks i fixed it Quote Link to comment https://forums.phpfreaks.com/topic/49594-solved-dynamically-create-list-value-entries/#findComment-243240 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.