如何使用mysqli获取总行数 [英] how to get the total row count with mysqli

查看:53
本文介绍了如何使用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获取总行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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