警告:mysqli_fetch_array() 期望参数 1 为 mysqli_result,给定字符串
这是我的代码,谁能告诉我出了什么问题吗?
$result ="SELECT * FROM report" ;
if(mysqli_query($cons, $result)) {
echo("
<div class='sc'>
<table id='to1' width='90%' border='0' cellspaceing='1' cellpadding='8' align='center'>
<tr bgcolor='#9B7272'>
<td > ID </td>
<td > first_name </td>
<td > last_name </td>
<td > phone </td>
<td > address </td>
<td > email </td>
<td > birthdate </td>
<td > gender </td>
<td > city </td>
<td > dr_name </td>
</tr>
");
while($row = mysqli_fetch_array($result))
{
$ID =$row['ID'];
$first_name =$row['first_name'];
$last_name =$row['last_name'];
$phone =$row['phone'];
$address =$row['address'];
$email =$row['email'];
$birthdate =$row['birthdate'];
$gender =$row['gender'];
$city =$row['city'];
$dr_name =$row['dr_name'];
echo " <tr bgcolor='#C7B8B8'>
Problem
您缺少如何将参数传递给mysqli_fetch_array() http://php.net/manual/en/mysqli-result.fetch-array.php.
Solution
因此,这一行:
if(mysqli_query($cons, $result)) {
应该
if($res = mysqli_query($cons, $result)) { // assign the return value of mysqli_query to $res
(FWIW, I'd go with $res = mysqli_query($cons, $result);
then do if($res) {
.)
然后做
while($row = mysqli_fetch_array($res)) // pass $res to mysqli_fetch_array instead of the query itself
Why?
你正在给予mysqli_fetch_array()
- 作为一个论点 -string
其中包含您的查询。事情不是这样的。你应该传递的返回值mysqli_query()
反而。因此,你也可以这样写:while($row = mysqli_fetch_array(mysqli_query($cons, $result))) {}
(但这不是建议,只是向您展示它是如何工作的)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)