2017-02-21 70 views
1

//變量$ stat_ip位於要檢查的表Hasoffers中if它位於列值network_start_ip和network_end_ip之間,它位於另一個名爲Blacklisted的表中。我需要編寫一個函數,通過訪問所有三個函數來幫助我做到這一點。

<?php 
     include('adodb/adodb.inc.php'); 
     mysql_connect("*****","***","***"); 
     mysql_select_db("********"); 
     $pl=mysql_query("SELECT stat_ip,stat_session_ip FROM Hasoffers"); 
     $count=mysql_num_rows($pl) 

      while($row=mysql_fetch_array($pl)) 
       { 
       $stat_ip=$row['stat_ip']; 

       echo fn($stat_ip)."<br>"; 
       } 

      $bip=mysql_query("SELECT inet_aton(network_start_ip),inet_aton(network_end_ip) FROM blacklisted"); 

      while($array=mysql_fetch_array($bip)) 
      { 
      $start_ip=$array['network_Start_ip']; 
      $end_ip = $array['netwrok_end_ip']; 

      } 


      function fn($stat_ip) 
      { 
       $result =mysql_query('SELECT stat_ip FROM Hasoffers where ($stat_ip BETWEEN INET_ATON(network_start_ip) AND INET_ATON(network_end_ip)'); 





     } 
     ?>php 

回答

0

您可以使用

之間
SELECT inet_aton(network_start_ip),inet_aton(network_end_ip) 
FROM blacklisted 
WHERE your_ip_column BETWEEN INET_ATON(network_start_ip) AND INET_ATON(network_end_ip) 

如果同時需要在一個單一的查詢選擇,你可以使用一個左連接上

SELECT a.stat_ip 
FROM Hasoffers as a 
LEFT JOIN blacklisted on as b on inet_aton(a.stat_ip) 
       between INET_ATON(b.network_start_ip) AND INET_ATON(b.network_end_ip) 
+0

但我如何訪問我的IP柱之間以及另一個表(network_start_ip&network end_ip)的列同時進行。因爲它們屬於兩個不同的表格。 –

+0

答覆已更新..希望是你在找什麼 – scaisEdge