如何检查数组查询中是否存在结果


How to check if result exist on array query

我遇到了一个让我发疯的问题。也许你可以帮我。我有这样的东西:

$result_listas = mysqli_query($link, "some mysql query");
while($row = mysqli_fetch_array($result_listas, MYSQLI_BOTH))
{
  for($i=$resultado_min['id']; $i<=$resultado_max['id']; $i++)
  { 
    if ($row[id]=$i) 
    {
    echo "The '$i' element exist in the array";
    }
    else
    {
    echo"$i does not exist in the query";
    }
  }
}

基本上,我想做的是检查"$i"是否作为ID存在于"$result_listas"查询中。我相信这很简单,但我一整天都在编程,我的大脑都融化了!谢谢大家!

更换

if ($row[id]=$i) 

带有

if ($row['id']==$i) // Note the single quotes and also the == operator

或者尝试

if(in_array($i, $row)){
    //It Exists
}

举个例子,试试:

$row2 = mysqli_fetch_array($result_listas, MYSQLI_BOTH);
for($i=$resultado_min['id']; $i<=$resultado_max['id']; $i++) { 
    if (in_array($i, $row2)){
        echo "The '$i' element is in the array"; 
    } else{echo"nada";} 
}