graham23s Posted May 31, 2007 Share Posted May 31, 2007 Hi Guys, on my registration page i have an array of all the countries: $country_list = array("---- Choose ----", "Afghanistan", "Albania", "Algeria", i echo them out like this: echo '<select name="country">'; foreach ($country_list as $value) { echo "<option value=\"$value\">$value</option>\n"; } echo '</select> instead of inserting the name of the country into mysql i was wanting to insert a number corresponding to that country like: $country_list = array("---- Choose ----", "1","Afghanistan", "2","Albania", "3","Algeria", instead of Afganistan it inputs 1 into mysql, in the INSERT query, would i just do $country[0] to put the number into mysql? i have tried this and it only inputs array for some reason? thanks guys Graham Quote Link to comment Share on other sites More sharing options...
marcus Posted May 31, 2007 Share Posted May 31, 2007 Do something as such: $ara = array("hello","hey","goodbye","bye"); $x = 1; echo "<select>\n"; foreach($ara as $value){ echo "<option value=\"$x\">$value</option>\n"; $x++; } echo "</select>\n"; Quote Link to comment Share on other sites More sharing options...
gabeg Posted May 31, 2007 Share Posted May 31, 2007 You could create a two-dimensional array I *think* $x = array("Afghanistan"=>"1","Albania"=>"2"); and then foreach($x as $v=>k) { echo "<option value=$k>$v</option>"; } Quote Link to comment Share on other sites More sharing options...
graham23s Posted May 31, 2007 Author Share Posted May 31, 2007 Thank guys, 2d array worked perfect. cheers Graham Quote Link to comment 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.