The $ip_list contains the values ​​of the subnets that I need to remove from the list. I remove the following most likely crooked way.

 $ip_list = array("37.13.","217.118.","207.46."); $top = $pdo->prepare('SELECT DISTINCT ip FROM logs ORDER BY ip DESC'); $top->execute(); while ($toppost = $top->fetch(PDO::FETCH_LAZY)){ $array[] = $toppost->ip; } for ($i = 0; $i <= count($ip_list); $i++){ for ($a = 0; $a <= count($array); $a++){ $b = explode(".", $array[$a]); $n = $b[0].".".$b[1]."."; if ($ip_list[$i] == $n){ } else{ echo $n."<br/>"; } } } 

But, it still displays unnecessary addresses, although I did not register anything in the if condition. What did I do wrong?)

  • one
    try WHERE ip NOT LIKE '37 .13.% ' - Ordman

1 answer 1

It can be like this

 $ip_list = array("37.13.","217.118.","207.46."); $query='SELECT DISTINCT ip FROM logs WHERE 1=1'; foreach($ip_list as $ip){ $query .= ' AND ip NOT LIKE "'.$ip.'%"'; } $query .= 'ORDER BY ip DESC'; $top = $pdo->prepare($query); $top->execute();