我正在尝试将列表中的 IP 地址与阻止的 IP 列表进行比较。如果 IP 地址等于 $blockedIP 数组中的地址,则该行不包含在列表中。该列表是从 mysqli_query 填充的。如果 IP 地址与数组中的一个匹配,我想做的是排除整行。
echo '<div class="genericTable"><h2>Downloaded Sermons Report</h2><table>';
$blockedIP = array('69.58.178.58', '173.199.115.123', '173.199.120.99');
foreach($blockedIP as $ip){
$sql = mysqli_query($db, "SELECT * FROM dl_log WHERE ipaddress <> '".$ip."'");
while($row = mysqli_fetch_assoc($sql)){
echo '<tr>';
if($row['ipaddress'] !== $ip){
foreach($row as $each){
echo '<td class="genericTable">'.$each.'</td>';
}
}
echo '</tr>';
}
}
echo '</table></div>';
我已经用几种不同的方式尝试了该脚本,要么获取整个列表,要么将每一行和每一列与数组进行比较,这使得表格看起来很夸张。我正在使用 foreach 将值与数组进行比较。我应该把它放在哪里? 谢谢。
最佳答案
What I would like to do is exclude the whole row if the IP address matches one in the array.
您有几个选择:
关于php - 将 MySQL 行与 PHP 数组值进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13939996/