查询picturei有一个名为blackListed的表,具有start_ip& amp;end_ip,我需要检查我的变量$ stat_ip(来自表格hasoffers的另一列)是否位于范围之间,即使用mySQL查询,即大于或等于start_ip,小于或小于last_ip或等于last_ip。我的查询就像以下$ result = mysql_query(" select inet_aton(network_start_ip),inet_aton(network_last_ip)来自blacklisted where'。$ stat_ip。"'inet_aton(network_start_ip)和inet_aton(netet_aton(netter_last_ip_ip)之间)。这确实返回0计数,这不是预期输出。对MySQL查询的帮助表示赞赏。
<?php
include('adodb/adodb.inc.php');
$link=mysql_connect("166.26.18.122","vcc","abcd1234");
mysql_select_db("vcc");
$pl=mysql_query("SELECT stat_ip fromHasoffers");
$count=mysql_num_rows($pl);
while($row=mysql_fetch_array($pl))
{
$stat_ip=$row['stat_ip'];
echo ip($stat_ip)."<br>";
$ip_Num=ip2long($stat_ip);
}
function blacklisted($ip_Num)
{
$result=mysql_query("Select inet_aton(network_start_ip),inet_aton(network_last_ip) from blacklisted where '".$ip_Num."' BETWEEN inet_aton(network_start_ip) AND inet_aton(network_last_ip)");
$count=mysql_num_rows($result);
return $count;
}
?>
您可以设置为以下行的IP2long(ipaddress)函数
**$ip_Num=str_replace('.','',$stat_ip);**
ip2long 是工作行 inet_aton() mySQL函数。 ip2long 是PHP功能例如:
$ ip = '10 .0.5.9';printf("%u n",ip2long($ ip));
167773449
您需要在hasoffers查询上执行inet_aton。像这样
$pl=mysql_query("SELECT inet_aton(stat_ip) from Hasoffers");
$count=mysql_num_rows($pl);
不做inet_aton $ stat_ip具有点数的值。例如192.168.0.1
所以您的第二个查询就像
Select inet_aton(network_start_ip),inet_aton(network_last_ip) from blacklisted where '192.168.0.1' BETWEEN inet_aton(network_start_ip) AND inet_aton(network_last_ip)
简短更改第一个查询,希望它可以解决您的问题。
更新
正如您所说的,您无法更改查询。尝试这个
$pl=mysql_query("SELECT stat_ip from Hasoffers");
while($row=mysql_fetch_array($pl))
{
$stat_ip=$row['stat_ip'];
echo ip($stat_ip)."<br>";
//for converting to LongInt
$ip_Num=ip2long($stat_ip);
}
// Now pass $ip_Num instead of $stat_ip in your function
function blacklisted($ip_Num)