如何使用mysqli获取总行数

how to get the total row count with mysqli(如何使用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获取总行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)