how to get the total row count with mysqli(如何使用mysqli获取总行数)
问题描述
我正在尝试了解 mysqli 扩展并使用谷歌搜索,但除了 php.net 有用之外,关于此的信息很少.
i am trying to understand mysqli extension and did google but got very few info on this except php.net which was helpful.
现在,我正在尝试使用如下的 mysql 扩展实现我所能实现的目标:
now after all this i am trying to achieve what i could with mysql extension which is as follows:
// MYSQL STYLE OF fetching array, query limit and perform total row count all at once
$sql = "SELECT SQL_CALC_FOUND_ROWS *, post.id as pid, bla bla FROM account ORDER BY pid ASC". $eb["array"]['querylimit'];
$result = mysql_query($sql, $eb["con"]);
$TotalRcount = mysql_fetch_row(mysql_query("SELECT FOUND_ROWS()"));
// Performing record count [current]
// $RecordCount = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
// read columns
}
使用 mysqli 我怎样才能做到这一点?我确定我错过了很多东西.请帮助我举例说明如何实现我的目标.
with mysqli how can i achieve this? am sure i am missing many things. please help me with example on how to achieve my goal.
推荐答案
使用 mysqli 你可以按照以下方式进行(假设 mysqli 对象已经创建——你也可以使用 过程方法,略有不同):
using mysqli you do it the following way (assuming the mysqli object is already created -- you can also use the procedure methods, just slightly different):
$sql = "SELECT SQL_CALC_FOUND_ROWS *, post.id as pid, bla bla
FROM account ORDER BY pid ASC". $eb["array"]['querylimit'];
$result = $mysqli->query($sql);
$TotalRcount = $result->num_rows;
while($row=$result->fetch_assoc()){
$col1 = $row['col1']; // col1 is a placeholder for whatever column you are reading
//read columns
}
这篇关于如何使用mysqli获取总行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用mysqli获取总行数


- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01