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

匿名 (未验证) 提交于 2019-12-03 02:44:02

问题:

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

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

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:

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()); }  


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!