Re: [PHP-DB] Select statement drops 10th digit during table lookup?

2003-06-13 Thread Doug Thompson
Why not use the built-in conversion functions in mysql?

>From the manual:

INET_NTOA(expr) 
Given a numeric network address (4 or 8 byte), returns the dotted-quad representation 
of the address as a string: 
mysql> SELECT INET_NTOA(3520061480);
   ->  "209.207.224.40"

INET_ATON(expr) 
Given the dotted-quad representation of a network address as a string, returns an 
integer that represents the numeric value of the address. Addresses may be 4 or 8 byte 
addresses: 
mysql> SELECT INET_ATON("209.207.224.40");
   ->  3520061480


Doug



On Fri, 13 Jun 2003 10:19:32 +0100, Ronan Chilvers wrote:

>Here's how I did it when playing with this...
>
>Table definition:-
>
>CREATE TABLE ip_list (
>  ip_from double default NULL,
>  ip_to double default NULL,
>  country_code char(2) default NULL,
>  country_name varchar(100) default NULL,
>  KEY ip_from (ip_from,ip_to,country_code,country_name)
>) TYPE=MyISAM;
>
>Basic code to query it (takes a parameter 'ip' as GET paramter):-
>   /*
>   IP Lookup script
>   * prints a country code and name for an ip in the $_GET array
>   */
>
>   //Vars & Constants
>   define("HOST","myhost");
>   define("USER","myuser");
>   define("PASS","mypassword");
>   define("DB","ips");
>   define("IP",$_GET["ip"]);
>
>   // Functions
>   function dbconnect() {
>   if (($conn=mysql_pconnect(HOST,USER,PASS))===false) {
>   die("Couldn't connect to server");
>   }
>   if (!mysql_select_db(DB,$conn)) {
>   die("Couldn't select database");
>   }
>   return $conn;
>   }
>   function dbclose($conn) {
>   if (!mysql_close($conn)) {
>   die("Couldn't close database connection");
>   }
>   return true;
>   }
>   function dosql($SQL) {
>   if (($result=mysql_query($SQL))===false) {
>   die("Couldn't do sql : $SQL");
>   }
>   return $result;
>   }
>
>   //Core
>   $SQL = "SELECT COUNTRY_NAME AS cn, COUNTRY_CODE AS cc FROM ips.ip_list WHERE 
> IP_NUM BETWEEN ip_from AND ip_to";
>
>   $conn = dbconnect();
>
>   $ip = "127.0.0.1";
>
>   $QSQL = str_replace("IP_NUM",sprintf("%u",ip2long(IP)),$SQL);
>   
>   $result = dosql($QSQL);
>   $data = mysql_fetch_array($result);
>
>   echo "ip:".IP."";
>   echo "cn:".$data["cn"]."";
>   echo "cc:".$data["cc"];
>
>   dbclose($conn);
>?>
>
>HTH !!
>
>Ronan
>e: [EMAIL PROTECTED]
>t: 01903 739 997
>w: www.thelittledot.com
>
>The Little Dot is a partnership of
>Ronan Chilvers and Giles Webberley
>
>-- 
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>



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



Re: [PHP-DB] Select statement drops 10th digit during table lookup?

2003-06-13 Thread Ronan Chilvers
Here's how I did it when playing with this...

Table definition:-

CREATE TABLE ip_list (
  ip_from double default NULL,
  ip_to double default NULL,
  country_code char(2) default NULL,
  country_name varchar(100) default NULL,
  KEY ip_from (ip_from,ip_to,country_code,country_name)
) TYPE=MyISAM;

Basic code to query it (takes a parameter 'ip' as GET paramter):-
";
echo "cn:".$data["cn"]."";
echo "cc:".$data["cc"];

dbclose($conn);
?>

HTH !!

Ronan
e: [EMAIL PROTECTED]
t: 01903 739 997
w: www.thelittledot.com

The Little Dot is a partnership of
Ronan Chilvers and Giles Webberley

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



Re: [PHP-DB] Select statement drops 10th digit during table lookup?

2003-06-13 Thread Jason Wong
On Friday 13 June 2003 15:48, G & E Holt wrote:
> I hope this is something easy I am overlooking but here goes:
>
> I have a table called:  country which has the following fields:
>
>  FieldType
>  ip_from  double(11,0)
>  ip_todouble(11,0)
>  country_code char(2)
>  country_name varchar(50)

Shouldn't you be using some INTEGER type instead of DOUBLE? An unsigned INT 
will just about handle it (2^32).

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
It seems like the less a statesman amounts to, the more he loves the flag.
*/


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



Re: [PHP-DB] Select statement drops 10th digit during table lookup?

2003-06-13 Thread Ronan Chilvers
On 13 Jun,2003 at  0:48 G & E Holt wrote:

> $resolved=$DB_site->query_first("SELECT * FROM country WHERE
> '$resolvingip' BETWEEN ip_from AND ip_to");

Don't think you should have the '' around the ip number.  Does that help?


Ronan
e: [EMAIL PROTECTED]
t: 01903 739 997
w: www.thelittledot.com

The Little Dot is a partnership of
Ronan Chilvers and Giles Webberley

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