小编典典

如何使用mysqli获取总行数

mysql

我试图了解mysqli扩展名,并做了谷歌,但除了php.net这是非常有用的很少信息。

现在毕竟这是我想要实现的MySQL扩展,如下所示:

// 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我怎么能做到这一点?我肯定我错过了很多事情。请以示例的方式帮助我,以实现我的目标。


阅读 358

收藏
2020-05-17

共1个答案

小编典典

使用mysqli,您可以通过以下方式进行操作(假设mysqli对象已创建-
您也可以使用过程方法,只是略有不同):

$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
}
2020-05-17