我遇到的问题来自下面列出的第4行代码。我收到一条错误
警告:
mysqli_fetch_array()
期望参数1为mysqli_result
,string
为
我没有将" "
或' '
中的变量包含在内,因此我不确定此时字符串识别的来源。可以告诉我如何解决这个错误?
$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)){
//...
}
}
答案 0 :(得分:5)
你有:
mysqli_fetch_array($query)
应该是:
mysqli_fetch_array($result)
同样在第3行你有:
if($query === FALSE) { die(mysql_error()); }
应该是:
if ($result === FALSE) { die(mysql_error()); }