Couldn't fetch Mysqli_result

后端 未结 1 1592
终归单人心
终归单人心 2021-01-18 10:10

I\'ve got this error

Warning: mysqli_fetch_array() [function.mysqli-fetch-array]: Couldn\'t fetch mysqli_result in /home/fights7/public_html/i

1条回答
  •  借酒劲吻你
    2021-01-18 11:04

    Straight away, it appears that you are calling mysqli_free_result() inside your fetch loop, so after the first loop iteration, your result resource has been closed and freed, and no more results will be available.

    while($articles_info = mysqli_fetch_array($articles_data)) {
      $json = array();
      $json['streamitem_id'] = $articles_info['streamitem_id'];
      $json['streamitem_content'] = $articles_info['streamitem_content'];
      $json['streamitem_timestamp'] = $articles_info['streamitem_timestamp'];
      // Don't do this!
      //mysqli_free_result($articles_data);
    }
    // If you need to, free it outside the loop
    mysqli_free_result($articles_data);
    

    I note that you're calling mysqli_fetch_array() without specifying MYSQLI_ASSOC, and so you're getting both numeric and associative keys back. If you are using everything in your JSON, you don't need to do all those assignments if you use MYSQLI_ASSOC or mysqli_fetch_assoc():

    while($articles_info = mysqli_fetch_assoc($articles_data)) {
      // No need for the $json array. Just use $articles_info directly
      // if you were going to json_encode() it.
    }
    

    0 讨论(0)
提交回复
热议问题