mysqli fetch_array() 只是将检索到的第一行数据转换为数组


mysqli fetch_array() is only turning first row of retrieved data into an array

似乎

正在发生的事情是$result_tag只保存检索到的sql数据的第一行。

当我在 SQl 上运行结果查询时,返回一个包含多行的表。但是,当我var_dump()它时,它只返回第一行,没有其他任何内容。

  while($row = $results->fetch_array(MYSQLI_BOTH)) {    
  echo ....stuff that dont matter
  //Now I want some SQL results based on a result from ^^^ $row['ID']
  $result = $conn->query("SELECT tags.Tag FROM tags WHERE tags.results_ID =".$row['ID'] );
  $result_tag = $result->fetch_array(MYSQLI_NUM); 
  //I got the results. Now I want to compare them to another array '$explode' 
  //and echo out elements that are the same
    foreach($explode as $explodeValue){
      foreach($result_tag as $tag){
        if($tag == $explodeValue){
          echo $explodeValue;
        }
      }
    }
}//end of 1st while

你想使用fetch_all(); fetch_array()只返回一行(作为数组)见 http://php.net/manual/en/mysqli-result.fetch-all.php

这实际上是最外面的人正在做的事情,一次获取一行fetch_array()

更改为

$result = $conn->query("SELECT * FROM tags WHERE results_ID =".$row['ID'] );