php 警告:mysqli_fetch_array() 期望参数 1 是 mysqli_result,对象在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40304560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:08:55  来源:igfitidea点击:

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

phpmysqli

提问by age saputra

I'm got a little bit problem when I try to run this code.

当我尝试运行此代码时遇到了一些问题。

My problem is on line 32:

我的问题在第 32 行

screenshot

截屏

回答by Lorence Hernandez

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

mysqli_fetch_array's 1st parameter must be a result of a query. what you are doing is you are you are passing the connection(which doesnt makes sense) and the query command itself.

mysqli_fetch_array 的第一个参数必须是查询的结果。你正在做的是你正在传递连接(这没有意义)和查询命令本身。

read the doc here:http://php.net/manual/en/mysqli-result.fetch-array.php

在这里阅读文档:http : //php.net/manual/en/mysqli-result.fetch-array.php

to fix this, execute the query first, then store the result to a variable then later fetch that variable.

要解决此问题,请先执行查询,然后将结果存储到变量中,然后再获取该变量。

$sql = "select * from privinsi";
$result = mysqli_query($connection,$sql);
while($r = mysqli_fetch_array($result)
{
    /// your code here
}

回答by Davinder Kumar

You write sql query but didn't execute.

您编写了 sql 查询但没有执行。

$sql = "select * from privinsi";
$results = myqli_query($connection,$sql);
while($r = mysqli_fetch_array($results){
   //enter your code here
}