php 警告:mysqli_fetch_array() 期望参数 1 是 mysqli_result,给定的字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23460096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:44:44  来源:igfitidea点击:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given

php

提问by emayne_designer

The problem i'm having is from the 4th line of code listed below. I get an error that says

我遇到的问题来自下面列出的第 4 行代码。我收到一个错误提示

Warning: mysqli_fetch_array()expects parameter 1 to be mysqli_result, stringgiven

警告:mysqli_fetch_array()期望参数 1 为mysqli_resultstring给定

I don't have the variable enclosed in " "or ' 'so I'm not sure where the string recognition is coming from at this point. Can tell me how to fix this error?

我没有变封闭在" "' '所以我不知道在哪里的字符串识别从在这一点到来。能告诉我如何解决这个错误吗?

$query = "SELECT * FROM questions WHERE id='question' LIMIT 5";
$result = mysqli_query($connection, $query);
if($query === FALSE) { die(mysql_error()); } 

while($row = mysqli_fetch_array($query)){
    $id = $row['id'];
    $thisQuestion = $row['question'];
    $question_id = $row['question_id'];
    $q = '<h2>'.$thisQuestion.'</h2>';
    $query2 = "SELECT * FROM answers WHERE question_id='$question' ORDER BY rand() LIMIT 5";
    while($row2 = mysqli_fetch_array($query2)){
        //...
    }
}

回答by Marcin Nabia?ek

You have:

你有:

 mysqli_fetch_array($query)

Should be:

应该:

mysqli_fetch_array($result) 

Also in line 3 you have:

同样在第 3 行中,您有:

if($query === FALSE) { die(mysql_error()); } 

Should be rather:

应该是:

if ($result === FALSE) { die(mysql_error()); }