Jump to content

Letting Users Pick The Country They Live In


bigjoe11a

Recommended Posts

I added an option to my web site. That users can update their profile. It adds all kinds of info like, User birth date, and crap like that. I wanted to add a drop down box where I have a text box. and let the users select the country they live in. I have a folder called country with a crap load of images for lots of countries. Well I'm trying to come up with an idea on just how to do this. The idea is when a user selects there country. The image show show on the page. and they can update their profile too. I guess the idea is to create a new file called, 'countries.php' and add an array to that called country. Then I would have to add them to the drop down box in some way...

$country = array('USA' => 'us_en.gif',);

Now the bigger problem I have is I have no way of knowing how to setup a drop down box with all the countries listed and the files names for each country. Any one have some thing all ready made up. With the images and the drop down box. Thanks AgainJoe

Link to comment
Share on other sites

That's simple. The foreach() loop is made for that

<select name="country"><?phpforeach($country as $name=>$code) {  echo "<option value=\"$code\">$name</option>";}?></select>

Of course, you can't add images to a <select> element. You could have a series of radio buttons:

<?php foreach($country as $name=>$code) { ?><input type="radio" name="country" value="<?php echo $name; ?>"> <img src="<?php echo $code; ?>" alt="<?php echo $name; ?>"> <?php echo $name; ?><?php } ?>

Link to comment
Share on other sites

Ok, that helps with one. Any ideas on the rest of it. I don't know how many countries there are. I need some way of knowing what image goes with what country.

Link to comment
Share on other sites

I thought you had an array of countries and images. The foreach loop maintains the association between the two. You just need one array that associated each country with an image, like you showed before. You can manually make that array.

$country = array('USA' => 'us_en.gif','Canada'=>'ca_en.gif','Spain'=>'es_es.gif' /* Add all the countries to the array */);

Link to comment
Share on other sites

Thanks. You added 2 more for me., Have a list of the rest of them. and the image names related to each conutry

Link to comment
Share on other sites

Here's a start:

United States of AmericaCanadaUnited KingdomAustraliaIndiaChina AfghanistanAlbaniaAlgeriaAmerican SamoaAndorraAngolaAnguillaAntigua & BarbudaArgentinaArmeniaArubaAustriaAzerbaijanBahamasBahrainBangladeshBarbadosBelarusBelgiumBelizeBeninBermudaBhutanBoliviaBosnia & HerzegovinaBotswanaBouvet Is.BrazilBritish Indian Ocean Terr.British Virgin Is.Brunei DarussalamBulgariaBurkina FasoBurundiCambodiaCameroonCape VerdeCayman IslandsCentral African RepublicChadChileChristmas Is.Cocos (Keeling) Is.ColombiaComorosCongoCook Is.Costa RicaCote D'ivoire (Ivory Coast)CroatiaCubaCyprusCzech RepublicDenmarkDjiboutiDominicaDominican RepublicEast TimorEcuadorEgyptEl SalvadorEquatorial GuineaEritreaEstoniaEthiopiaFalkland Is. (Malvinas)Faroe Is.FijiFinlandFranceFrench GuianaFrench PolynesiaFrench Southern TerritoriesGabonGambiaGeorgiaGermanyGhanaGibraltarGreeceGreenlandGrenadaGuadeloupeGuamGuatemalaGuineaGuinea-BissauGuyanaHaitiHeard & McDonald Is.HondurasHong KongHungaryIcelandIndonesiaIraqIrelandIslamic Republic of IranIsraelItalyJamaicaJapanJordanKazakhstanKenyaKiribatiKorea, North (DPRK)Korea, South (Rep. of)KuwaitKyrgyzstanLao People's Democratic Rep.LatviaLebanonLesothoLiberiaLibyan Arab JamahiriyaLiechtensteinLithuaniaLuxembourgMacauMadagascarMalawiMalaysiaMaldivesMaliMaltaMarshall Is.MartiniqueMauritaniaMauritiusMayotteMexicoMicronesiaMoldova, Republic ofMonacoMongoliaMontserratMoroccoMozambiqueMyanmarNamibiaNauruNepalNetherlandsNetherlands AntillesNew CaledoniaNew ZealandNicaraguaNigerNigeriaNiueNorfolk Is.Northern Mariana Is.NorwayOmanPakistanPalauPanamaPapua New GuineaParaguayPeruPhilippinesPitcairnPolandPortugalPuerto RicoQatarReunionRomaniaRussian FederationRwandaS. Georgia & the S. Sandwich Is.SamoaSan MarinoSao Tome & PrincipeSaudi ArabiaSenegalSeychellesSierra LeoneSingaporeSlovakiaSloveniaSolomon Is.SomaliaSouth AfricaSpainSri LankaSt. HelenaSt. Kitts & NevisSt. LuciaSt. Pierre & MiquelonSt. Vincent & the GrenadinesSudanSurinameSvalbard & Jan Mayen Is.SwazilandSwedenSwitzerlandSyrian Arab RepublicTaiwan, Province of ChinaTajikistanTanzania, United Rep. ofThailandTogoTokelauTongaTrinidad & TobagoTunisiaTurkeyTurkmenistanTurks & Caicos Is.TuvaluUgandaUkraineUnited Arab EmiratesU.S. Virgin Is.U.S. Minor Outlying Is.UruguayUzbekistanVanuatuVenezuelaViet NamWallis & Futuna Is.Western SaharaYemenYugoslaviaZaireZambiaZimbabwe
Link to comment
Share on other sites

Thanks justsome, How ever that list doesn't include the names of each image for each country. So I don't know how I'm going to do this. Thanks for your help. I have all the flags all ready. I just want to match them up with each country. The images I do have are from Portal XL 5.0 Premod 0.4

Link to comment
Share on other sites

Assuming the images are named with the country code, then you're going to need to look up the country code for each one and build the array yourself. You can either spend time looking for exactly what you need and possibly not find it, or spend time building what you need.

Link to comment
Share on other sites

Well I was hoping some one would have made one all ready, when I get this done I'll have to add it to my web site. So others can get it when they need it. Thanks for your help. Joe

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...