rumon007 Posted January 21, 2009 Share Posted January 21, 2009 I have created a list box writing a code as follows: <select name=\"select_to_edit\"> <option selected>- -Select a Country- -</option> </select> And I have to variables named $id and $country_name. Now I want to show the values of the $country_name variable in the List Box. Please someone help me to write the code. Quote Link to comment https://forums.phpfreaks.com/topic/141774-need-help-to-add-values-in-list-box/ Share on other sites More sharing options...
lonewolf217 Posted January 21, 2009 Share Posted January 21, 2009 where are you getting the values from ? array ... database ... text file ? details are always helpful Quote Link to comment https://forums.phpfreaks.com/topic/141774-need-help-to-add-values-in-list-box/#findComment-742180 Share on other sites More sharing options...
Maq Posted January 21, 2009 Share Posted January 21, 2009 where are you getting the values from ? array ... database ... text file ? He did... And I have to variables named $id and $country_name. I'm guessing you want the option to be $country_name and the value that you reference the $id. Try something like: Quote Link to comment https://forums.phpfreaks.com/topic/141774-need-help-to-add-values-in-list-box/#findComment-742187 Share on other sites More sharing options...
prcollin Posted January 21, 2009 Share Posted January 21, 2009 while ($row = mysql_fetch_array($result)) { echo "<option value="" . $row['id'] . "">" . $row['country_name] . "</option> that is just for the drop down menu i am assuming you have the rest of the php code to pull the values from the database? Quote Link to comment https://forums.phpfreaks.com/topic/141774-need-help-to-add-values-in-list-box/#findComment-742194 Share on other sites More sharing options...
rumon007 Posted January 21, 2009 Author Share Posted January 21, 2009 both variables get all data from a database. for example - $id $country_name --------------------------- 1 USA 2 UK 3 India 4 Bangladesh Quote Link to comment https://forums.phpfreaks.com/topic/141774-need-help-to-add-values-in-list-box/#findComment-742378 Share on other sites More sharing options...
Maq Posted January 21, 2009 Share Posted January 21, 2009 Then do what prcollin suggested: echo ""; while ($row = mysql_fetch_array($result)) { echo "{$row['country_name']} } echo ""; Quote Link to comment https://forums.phpfreaks.com/topic/141774-need-help-to-add-values-in-list-box/#findComment-742406 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.