调用未定义的函数mysqli_result() [英] Call to undefined function mysqli_result()

查看:39
本文介绍了调用未定义的函数mysqli_result()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对mysqli_result()有问题->(例如mysql_result) (调用未定义的函数mysqli_result())

I have problem with mysqli_result() -> (ex mysql_result) (Call to undefined function mysqli_result() )

我的代码:

$per_page = 6;
$pages_query = mysqli_query($conn, 'SELECT COUNT(id) FROM users');  
$pages = ceil(mysqli_result($pages_query, 0) / $per_page);

浏览器错误:

致命错误:在第11行的/Applications/MAMP/htdocs/bootstrap/pagination.php中调用未定义的函数mysqli_result()

Fatal error: Call to undefined function mysqli_result() in /Applications/MAMP/htdocs/bootstrap/pagination.php on line 11

提前谢谢!

推荐答案

已更新:

mysql_result() 相对,没有mysqli_result() MySQLi中可用的功能.现在有两种方法可以解决您的问题.

Updated:

As opposed to mysql_result(), there's no mysqli_result() function available in MySQLi. Now there are two approaches to solve your problem.

方法(1):

使用 mysqli_fetch_array() 函数获得总数行.您的代码应如下所示:

Use mysqli_fetch_array() function to get the total number of rows. Your code should be like this:

$per_page = 6;
$pages_query = mysqli_query($conn, 'SELECT COUNT(id) FROM users'); 
$row = mysqli_fetch_array($pages_query);
$pages = ceil($row[0] / $per_page);

方法(2):

或者,您可以使用 mysqli_num_rows() 来获取结果集中的总行数.但是,您需要通过以下方式更改查询,

Alternatively, you can use mysqli_num_rows() to get the total number of rows from the result set. However, you need to change your query in the following way,

SELECT id FROM users

所以您的代码应如下所示:

So your code should be like this:

$per_page = 6;
$pages_query = mysqli_query($conn, 'SELECT id FROM users');  
$pages = ceil(mysqli_num_rows($pages_query) / $per_page);

这篇关于调用未定义的函数mysqli_result()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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