List:General Discussion« Previous MessageNext Message »
From:Rhino Date:November 19 2005 2:39pm
Subject:Re: Mysql Finding the country name from country prefix
View as plain text  
----- Original Message ----- 
From: "abhishek jain" <mail@stripped>
To: <mysql@stripped>
Sent: Saturday, November 19, 2005 8:10 AM
Subject: Mysql Finding the country name from country prefix


> Hi Friends,
> I have a ticky mysql problem.
> I need to find the country name from the country prefix so eg. i have a
> mysql table with prefix and name as the coumns and with datas like :
> Prefix,  Name
> 1          USA
> 11        XYZ
> 44        UK
> 91        India
> 92        Pakistan
> 123      ZXF
> and i have a number like 911122334455 and i need t match that to india.
> I cannt do that directly by this statement select name from
> country_table where prefix='91'; for the simple reason as i do not have
> the length or the no. of digits the prefix is beforehand.
> Pl. help me out.
> Quick help will be appreciated.

You are not explaining your problem very clearly at all, particularly why 
you think this is a MySQL problem.

It looks to me as if you are trying to parse a phone number and determine 
from the first few digits what country that phone number represents.  You 
already have a table that gives you the country code for each country and it 
shows clearly that 91 is the country code for India. As for the length of 
the country code, surely you can easily calculate that 91 has two digits in 
it.

If you are saying that you have only a string of digits and need to 
determine the country in which that phone number originates without any 
further information, all I can say is good luck. The fact is that people 
write their phone numbers in many different ways. Here in Canada, if I'm 
giving my number to someone who lives within my city or region, I'm likely 
to give them only the last seven digits, e.g. 5551212. If I wanted to give 
my number to someone farther away in Canada, the US, or the Caribbean, I'd 
give them 5195551212 since we all share the same country code, 1. If I 
wanted to give my number to someone in some other foreign country, I'd give 
them 15195551212. So, right away, you have three different ways to express 
the phone number all of which are accurate and complete in their own 
context. If you parsed the first example, you might assume that I am in 
Brazil, because '55' is the country code for Brazil. (Country codes '5' and 
'555' are not in use at present.) If you parsed 519-555-1212, you wouldn't 
find anything because there is no country code '5', '51', or '519' currently 
in use. If you tried to parse '15195551212', you'd think I was in the US, 
Canada, or one of the Caribbean countries since '1' is the code for those 
countries. (There is is no '15' or '151' country code at present.) 
Therefore, the phone number _by itself_ is next to useless to you unless you 
are absolutely certain that the phone number is complete and includes the 
country code, area/city code and local number.

None of that is a MySQL problem. The problem lies in your data acquisition 
technique. If you have to parse phone numbers, the input forms you use have 
to ensure that the user supplies the entire phone number; ideally, that 
number would be supplied in different fields, one of which would be the 
country code. Then you would have no problem except making sure that the 
user has supplied their own phone number and not someone elses. (The number 
I used in my examples, 15195551212, is the directory assistance phone number 
for my area, not my own phone number.)

So, unless I've misunderstood what you are asking, I don't think we can help 
you very much. There is no function in MySQL or any other database I have 
used that can calculate the country code accurately given only a phone 
number that may or may not be complete.

Rhino




-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.4/175 - Release Date: 18/11/2005

Thread
Mysql Finding the country name from country prefixabhishek jain19 Nov
  • Re: Mysql Finding the country name from country prefixRhino19 Nov
    • Re: Mysql Finding the country name from country prefixMichael Stassen19 Nov
    • Re: Mysql Finding the country name from country prefixBjörn Persson19 Nov
  • Re: Mysql Finding the country name from country prefixPeter Brawley19 Nov
    • Re: Mysql Finding the country name from country prefixMichael Stassen19 Nov
  • Re: Mysql Finding the country name from country prefixMichael Stassen19 Nov
  • Re: Mysql Finding the country name from country prefixRhino19 Nov
    • Re: Mysql Finding the country name from country prefixMichael Stassen19 Nov
  • Re: Mysql Finding the country name from country prefixRhino19 Nov
    • Re: Mysql Finding the country name from country prefixMichael Stassen20 Nov
      • Re: Mysql Finding the country name from country prefixJasper Bryant-Greene20 Nov
        • Re: Mysql Finding the country name from country prefixMichael Stassen20 Nov
        • Re: Mysql Finding the country name from country prefixBjörn Persson20 Nov