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 Link to comment https://forums.phpfreaks.com/topic/53668-solved-array-question/ 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"; Link to comment https://forums.phpfreaks.com/topic/53668-solved-array-question/#findComment-265298 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>"; } Link to comment https://forums.phpfreaks.com/topic/53668-solved-array-question/#findComment-265299 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 Link to comment https://forums.phpfreaks.com/topic/53668-solved-array-question/#findComment-265462 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.