brown2005 Posted June 14, 2006 Share Posted June 14, 2006 function select_country($c) { $countries = array('', 'Afghanistan', 'Albania', 'American Samoa', 'Andorra', 'Antigua', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Bolivia', 'Bosnia-Herzegovina', 'Brazil', 'Brunei Darussalam', 'Bulgaria', 'Cambodia', 'Canada', 'Chile', 'China', 'Colombia', 'Costa Rica', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Ecuador', 'Egypt', 'El Salvador', 'England', 'Estonia', 'Falkland Islands', 'Fiji', 'Finland', 'France', 'French Guyana', 'Georgia', 'Germany', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guatemala', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Malaysia', 'Maldives', 'Malta', 'Mauritius', 'Mexico', 'Mongolia', 'Morocco', 'Nepal', 'Netherlands', 'New Zealand', 'Nicaragua', 'North Korea', 'Norway', 'Oman', 'Pakistan', 'Panama', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Romania', 'Russian Federation', 'Saudi Arabia', 'Singapore', 'Slovak Republic', 'Slovenia', 'South Africa', 'South Korea', 'Spain', 'Sri Lanka', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Thailand', 'Tunisia', 'Turkey', 'Turkmenistan', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay', 'Uzbekistan', 'Venezuela', 'Vietnam', 'Yemen', 'Yugoslavia', 'Zimbabwe'); $SelectCountry = "<select name='country' class='text'>\n\t"; while(list(,$v) = each($countries)) { if($c == $v) { $SelectCountry .= "<option value=\"$v\" selected>$v </option>\n\t"; } else { $SelectCountry .= "<option value=\"$v\">$v </option>\n\t"; } } $SelectCountry .= "</select>"; return $SelectCountry;}how can i change the array to read from say table countries in mysql Link to comment https://forums.phpfreaks.com/topic/11966-array/ Share on other sites More sharing options...
trq Posted June 14, 2006 Share Posted June 14, 2006 learn to use [a href=\"http://php.net/mysql_query\" target=\"_blank\"]mysql_query[/a], [a href=\"http://php.net/mysql_fetch_array\" target=\"_blank\"]mysql_array[/a] and loop through your result creating an array. Link to comment https://forums.phpfreaks.com/topic/11966-array/#findComment-45468 Share on other sites More sharing options...
.josh Posted June 14, 2006 Share Posted June 14, 2006 [code]$sql = "select country from tablename";$result = mysql_query($sql);$SelectCountry = "<select name='country' class='text'>\n\t";while ($countries = mysql_fetch_array($result)) { $SelectCountry.="<option value='".$countries['country']."'>".$countries['country']."</option>";}$SelectCountry.="</select>";[/code] Link to comment https://forums.phpfreaks.com/topic/11966-array/#findComment-45494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.