警告:mysqli_fetch_array()期望参数1为sqmyli_result,给定字符串

时间:2022-02-06 20:13:48

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, string given

警告:mysqli_fetch_array()期望参数1为sqmyli_result,给定字符串

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)){
        //...
    }
}

1 个解决方案

#1


4  

You have:

你有:

 mysqli_fetch_array($query)

Should be:

应该是:

mysqli_fetch_array($result) 

Also in line 3 you have:

在第三行,你有:

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

Should be rather:

应该不是:

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

#1


4  

You have:

你有:

 mysqli_fetch_array($query)

Should be:

应该是:

mysqli_fetch_array($result) 

Also in line 3 you have:

在第三行,你有:

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

Should be rather:

应该不是:

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