错误mysqli_fetch_array()期望参数1为mysqli_result,给出字符串 [英] error mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given

查看:435
本文介绍了错误mysqli_fetch_array()期望参数1为mysqli_result,给出字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这是我的密码,谁能告诉我哪里错了?

this is my codes can anyone tell me what is wrong?

$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'>

推荐答案

问题

您缺少如何将参数传递给 mysqli_fetch_array() .

You are missing how to pass the argument to mysqli_fetch_array().

解决方案

因此,此行:

if(mysqli_query($cons, $result)) {

应该是

if($res = mysqli_query($cons, $result)) { // assign the return value of mysqli_query to $res

(FWIW,我先选$res = mysqli_query($cons, $result);然后做if($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

为什么?

您将mysqli_fetch_array()-包含您的查询的string作为自变量.那不是它的工作原理.您应该改为传递mysqli_query()的返回值.因此,您还可以编写:while($row = mysqli_fetch_array(mysqli_query($cons, $result))) {}(但不建议这样做,只是为了向您展示它的工作原理.)

You were giving to mysqli_fetch_array() - as an argument - the string that contains your query. That's not how it works. You should pass the return value of mysqli_query() instead. Therefore, you could also write: while($row = mysqli_fetch_array(mysqli_query($cons, $result))) {} (but it's not adviced, it is just to show you how it works).

这篇关于错误mysqli_fetch_array()期望参数1为mysqli_result,给出字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆