0

だから私はこのウェブサイトhttp://www.mediacollege.com/internet/samples/html/country-list.htmlのようなこのオプションの国を持っていて、テーブルmysqlにフィールド国を持っています。mysql のフィールドの国を読み取り、オプションで mysql のフィールドと一致する国を選択したい。

私はmysqlデータベースを読むのに問題はありません.私の質問は、そのような巨大なリストで正しいオプションの国をどのように選択するかです. 一つ一つ作るのは現実的ではない

4

2 に答える 2

1

すべてのオプションを実行するサイクルが必要です..のように

foreach($countries as $key=>$value){
 echo '<option value="'.$key.'" '.($key == $selected_country ? 'selected=selected':'').'>'.$value.'</option>';
}

複数選択を使用する場合は、比較の代わりに使用しますin_array

于 2012-04-12T15:08:14.177 に答える
0
<?php

$Countries = array(
"AF"    =>  "Afghanistan",
"AL"    =>  "Albania",
"DZ"    =>  "Algeria",
"AS"    =>  "American Samoa",
"AD"    =>  "Andorra",
"AG"    =>  "Angola",
"AI"    =>  "Anguilla",
"AG"    =>  "Antigua &amp; Barbuda",
"AR"    =>  "Argentina",
"AA"    =>  "Armenia",
"AW"    =>  "Aruba",
"AU"    =>  "Australia",
"AT"    =>  "Austria",
"AZ"    =>  "Azerbaijan",
"BS"    =>  "Bahamas",
"BH"    =>  "Bahrain",
"BD"    =>  "Bangladesh",
"BB"    =>  "Barbados",
"BY"    =>  "Belarus",
"BE"    =>  "Belgium",
"BZ"    =>  "Belize",
"BJ"    =>  "Benin",
"BM"    =>  "Bermuda",
"BT"    =>  "Bhutan",
"BO"    =>  "Bolivia",
"BL"    =>  "Bonaire",
"BA"    =>  "Bosnia &amp; Herzegovina",
"BW"    =>  "Botswana",
"BR"    =>  "Brazil",
"BC"    =>  "British Indian Ocean Territory",
"BN"    =>  "Brunei",
"BG"    =>  "Bulgaria",
"BF"    =>  "Burkina Faso",
"BI"    =>  "Burundi",
"KH"    =>  "Cambodia",
"CM"    =>  "Cameroon",
"CA"    =>  "Canada",
"IC"    =>  "Canary Islands",
"CV"    =>  "Cape Verde",
"KY"    =>  "Cayman Islands",
"CF"    =>  "Central African Republic",
"TD"    =>  "Chad",
"CD"    =>  "Channel Islands",
"CL"    =>  "Chile",
"CN"    =>  "China",
"CI"    =>  "Christmas Island",
"CS"    =>  "Cocos Island",
"CO"    =>  "Colombia",
"CC"    =>  "Comoros",
"CG"    =>  "Congo",
"CK"    =>  "Cook Islands",
"CR"    =>  "Costa Rica",
"CT"    =>  "Cote D'Ivoire",
"HR"    =>  "Croatia",
"CU"    =>  "Cuba",
"CB"    =>  "Curacao",
"CY"    =>  "Cyprus",
"CZ"    =>  "Czech Republic",
"DK"    =>  "Denmark",
"DJ"    =>  "Djibouti",
"DM"    =>  "Dominica",
"DO"    =>  "Dominican Republic",
"TM"    =>  "East Timor",
"EC"    =>  "Ecuador",
"EG"    =>  "Egypt",
"SV"    =>  "El Salvador",
"GQ"    =>  "Equatorial Guinea",
"ER"    =>  "Eritrea",
"EE"    =>  "Estonia",
"ET"    =>  "Ethiopia",
"FA"    =>  "Falkland Islands",
"FO"    =>  "Faroe Islands",
"FJ"    =>  "Fiji",
"FI"    =>  "Finland",
"FR"    =>  "France",
"GF"    =>  "French Guiana",
"PF"    =>  "French Polynesia",
"FS"    =>  "French Southern Territory",
"GA"    =>  "Gabon",
"GM"    =>  "Gambia",
"GE"    =>  "Georgia",
"DE"    =>  "Germany",
"GH"    =>  "Ghana",
"GI"    =>  "Gibraltar",
"GB"    =>  "Great Britain",
"GR"    =>  "Greece",
"GL"    =>  "Greenland",
"GD"    =>  "Grenada",
"GP"    =>  "Guadeloupe",
"GU"    =>  "Guam",
"GT"    =>  "Guatemala",
"GN"    =>  "Guinea",
"GY"    =>  "Guyana",
"HT"    =>  "Haiti",
"HW"    =>  "Hawaii",
"HN"    =>  "Honduras",
"HK"    =>  "Hong Kong",
"HU"    =>  "Hungary",
"IS"    =>  "Iceland",
"IN"    =>  "India",
"ID"    =>  "Indonesia",
"IA"    =>  "Iran",
"IQ"    =>  "Iraq",
"IE"    =>  "Ireland",
"IM"    =>  "Isle of Man",
"IL"    =>  "Israel",
"IT"    =>  "Italy",
"JM"    =>  "Jamaica",
"JP"    =>  "Japan",
"JO"    =>  "Jordan",
"KZ"    =>  "Kazakhstan",
"KE"    =>  "Kenya",
"KI"    =>  "Kiribati",
"NK"    =>  "Korea North",
"KR"    =>  "Korea South",
"KW"    =>  "Kuwait",
"KG"    =>  "Kyrgyzstan",
"LA"    =>  "Laos",
"LV"    =>  "Latvia",
"LB"    =>  "Lebanon",
"LS"    =>  "Lesotho",
"LR"    =>  "Liberia",
"LY"    =>  "Libya",
"LI"    =>  "Liechtenstein",
"LT"    =>  "Lithuania",
"LU"    =>  "Luxembourg",
"MO"    =>  "Macau",
"MK"    =>  "Macedonia",
"MG"    =>  "Madagascar",
"MY"    =>  "Malaysia",
"MW"    =>  "Malawi",
"MV"    =>  "Maldives",
"ML"    =>  "Mali",
"MT"    =>  "Malta",
"MH"    =>  "Marshall Islands",
"MQ"    =>  "Martinique",
"MR"    =>  "Mauritania",
"MU"    =>  "Mauritius",
"ME"    =>  "Mayotte",
"MX"    =>  "Mexico",
"MI"    =>  "Midway Islands",
"MD"    =>  "Moldova",
"MC"    =>  "Monaco",
"MN"    =>  "Mongolia",
"MS"    =>  "Montserrat",
"MA"    =>  "Morocco",
"MZ"    =>  "Mozambique",
"MM"    =>  "Myanmar",
"NA"    =>  "Nambia",
"NU"    =>  "Nauru",
"NP"    =>  "Nepal",
"AN"    =>  "Netherland Antilles",
"NL"    =>  "Netherlands",
"NV"    =>  "Nevis",
"NC"    =>  "New Caledonia",
"NZ"    =>  "New Zealand",
"NI"    =>  "Nicaragua",
"NE"    =>  "Niger",
"NG"    =>  "Nigeria",
"NW"    =>  "Niue",
"NF"    =>  "Norfolk Island",
"NO"    =>  "Norway",
"OM"    =>  "Oman",
"PK"    =>  "Pakistan",
"PW"    =>  "Palau Island",
"PS"    =>  "Palestine",
"PA"    =>  "Panama",
"PG"    =>  "Papua New Guinea",
"PY"    =>  "Paraguay",
"PE"    =>  "Peru",
"PH"    =>  "Philippines",
"PO"    =>  "Pitcairn Island",
"PL"    =>  "Poland",
"PT"    =>  "Portugal",
"PR"    =>  "Puerto Rico",
"QA"    =>  "Qatar",
"RE"    =>  "Reunion",
"RO"    =>  "Romania",
"RU"    =>  "Russia",
"RW"    =>  "Rwanda",
"NT"    =>  "St Barthelemy",
"EU"    =>  "St Eustatius",
"HE"    =>  "St Helena",
"KN"    =>  "St Kitts-Nevis",
"LC"    =>  "St Lucia",
"MB"    =>  "St Maarten",
"PM"    =>  "St Pierre &amp; Miquelon",
"VC"    =>  "St Vincent &amp; Grenadines",
"SP"    =>  "Saipan",
"SO"    =>  "Samoa",
"AS"    =>  "Samoa American",
"SM"    =>  "San Marino",
"ST"    =>  "Sao Tome &amp; Principe",
"SA"    =>  "Saudi Arabia",
"SN"    =>  "Senegal",
"SC"    =>  "Seychelles",
//"S0"  =>  "Serbia",
"SL"    =>  "Sierra Leone",
"SG"    =>  "Singapore",
"SK"    =>  "Slovakia",
"SI"    =>  "Slovenia",
"SB"    =>  "Solomon Islands",
"OI"    =>  "Somalia",
"ZA"    =>  "South Africa",
"ES"    =>  "Spain",
"LK"    =>  "Sri Lanka",
"SD"    =>  "Sudan",
"SR"    =>  "Suriname",
"SZ"    =>  "Swaziland",
"SE"    =>  "Sweden",
"CH"    =>  "Switzerland",
"SY"    =>  "Syria",
"TA"    =>  "Tahiti",
"TW"    =>  "Taiwan",
"TJ"    =>  "Tajikistan",
"TZ"    =>  "Tanzania",
"TH"    =>  "Thailand",
"TG"    =>  "Togo",
"TK"    =>  "Tokelau",
"TO"    =>  "Tonga",
"TT"    =>  "Trinidad &amp; Tobago",
"TN"    =>  "Tunisia",
"TR"    =>  "Turkey",
"TU"    =>  "Turkmenistan",
"TC"    =>  "Turks &amp; Caicos Is",
"TV"    =>  "Tuvalu",
"UG"    =>  "Uganda",
"UA"    =>  "Ukraine",
"AE"    =>  "United Arab Emirates",
"GB"    =>  "United Kingdom",
"US"    =>  "United States of America",
"UY"    =>  "Uruguay",
"UZ"    =>  "Uzbekistan",
"VU"    =>  "Vanuatu",
"VA"    =>  "Vatican City State",
"VE"    =>  "Venezuela",
"VN"    =>  "Vietnam",
"VB"    =>  "Virgin Islands (Brit)",
"VA"    =>  "Virgin Islands (USA)",
"WF"    =>  "Wallis &amp; Futana Is",
"YE"    =>  "Yemen",
"ZR"    =>  "Zaire",
"ZM"    =>  "Zambia",
"ZW"    =>  "Zimbabwe"
);

これは私が以前に作成したものです。これを使用してドロップダウンを生成し、データベースから読み取るときに、2 文字の国コードをキーとして使用できます。

$Countries[$mysqlCountryCode];

完全な国名を取得します。

それは間違いなくエレガントではありませんが、データをmysqlテーブルまたは配列のどこかに保存する必要があります。

于 2012-04-12T15:11:06.797 に答える