Select statement drops 10th digit during table lookup?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I hope this is something easy I am overlooking but here goes:

I have a table called:  country which has the following fields:

 Field                Type
 ip_from              double(11,0)
 ip_to                double(11,0)
 country_code         char(2)
 country_name         varchar(50)

IP_FROM          NUMERICAL (DOUBLE)    Beginning of IP address range.
IP_TO            NUMERICAL (DOUBLE)    Ending of IP address range.
COUNTRY_CODE     CHAR(2)               Two-character country code based on
ISO 3166.
COUNTRY_NAME     VARCHAR(50)           Country name based on ISO 31

Here are a few lines from the country table which starts at 33996344  and
ends at    :
 ip_from  ip_to         country_code  country_name
33996344 33996351         GB           UNITED KINGDOM
50331648 83886079         US           UNITED STATES
94585424 94585439         SE           SWEDEN
<approx 65000 rows >
3714175488 3714175743     DK           DENMARK
3715104768 3715629055     JP           JAPAN
3717201920 3718840319     KR           KOREA, REPUBLIC OF

The IP_FROM and IP_TO fields of the database are numeric representations of
the dotted IP address.

The formula to convert an IP Address of the form A.B.C.D to an IP Number is:

     IP Number = A x (256*256*256) + B x (256*256) + C x 256 + D

So here is what I do in PHP:

$resolvingip=sprintf("%u",ip2long($ip));
$resolved=$DB_site->query_first("SELECT * FROM country WHERE '$resolvingip'
BETWEEN ip_from AND ip_to");
$resolvecountry = $resolved[country_code];

so I type in:  213.21.158.96  and $resolvingip shows as: 3574963808

when I check $resolved[ip_from] I find out the SELECT statement looks up
this line:

335544320 369098751 US UNITED STATES
instead of looking up this line:
3574956032 3574972415 IT ITALY

which really makes me think the SELECT statement is dropping the last
digit...

I tried ip:  10.25.215.30 and $resolvingip shows as 169465630 which looks up
correctly since it is only 9 digits.

When I try ip: 68.109.155.135 $resolvingip shows as 1148033927 but the
SELECT statement drops the last digit and goes to a 9 digit again:
114803392

Any help is greatly appreciated..

Thanks!









-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux