943,910 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 9980
  • PHP RSS
Jul 3rd, 2006
0

Country code conversion

Expand Post »
Right now In my country database county code vlaues are stored in 3 digits.
So we need to convert the country code three digite to two digit

Please write a php function in an independent php file that will contain an array that will map the current 3 letter country codes in the countries_master.value to 2 letter ISO standard codes in uppercase


Thanks
vssp
Similar Threads
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006
Jul 3rd, 2006
1

Re: Country code conversion

Sounds kinda like a homework assignment...

Why not just do an UPDATE in SQL. That's not PHP, but it's the easiest way to do it.
Reputation Points: 23
Solved Threads: 23
Posting Pro in Training
Puckdropper is offline Offline
494 posts
since Jul 2004
Jul 3rd, 2006
0

Re: Country code conversion

lol.. yes, it does sound like a homework assignment..

Like Puckdropper said, its better to update the SQL rather than PHP. If you're set on PHP (I dont want to do your homework for you ) however its a very simple task.

Heres the link to php documentation on the array notation/syntax:
http://php.net/manual/en/language.types.array.php

You can use the array notation, or array functions (http://php.net/array) to create an array.

Your array should be a simple 1 dimensional array (each value has a single key) that links either:

1) The primary key of countries_master.value with the corresponding 2 digit ISO country code, or

2) The 3 Digit country code field in countries_master.value with the corresponding 2 Digit ISO country code

Knowing the key in an array means you can extract the corresponding value using $array[$key];
So if your array has the 3 digit county codes as index, then $array[$countycode3digits] should retrieve the 2 digit country code value.

It's good practice to first check if the key exists before trying to retieve an array value using the key.
The function to check if a key exists in an array can be found in the array function list: http://php.net/array
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Jul 4th, 2006
0

Re: Country code conversion

Thanks

Sorry I am not give you home work .

vssp
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006
Jul 4th, 2006
0

Re: Country code conversion

Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How to mail a report automatically from web.
Next Thread in PHP Forum Timeline: Help With Messages in Mysql Stop Overwriting





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC