繁体   English   中英

计算查询中的行数

[英]count the number of rows in a query

我在工作页面中分开了此功能。

public function countRow(){
        $id = $_SESSION['id'];
        $num = 1;
        $query = "SELECT count(*) from `auditsummary` where bizID=? AND statusID=?";
        $sql = $this->db->prepare($query);
        $sql->bindParam(1,$id);
        $sql->bindParam(2,$num);
        $sql->execute();


    }

我真正想在此函数中执行的操作是计算查询结果的行数,但我不知道如何执行以及如何返回值。

当您对查询使用PDOStatement时,执行后,您可以使用

$count = $sql->rowCount();

详细信息: http : //php.net/manual/en/pdostatement.rowcount.php

要返回结果,您可以执行以下操作:

return $count;

有关此信息: http : //php.net/manual/en/function.return.php

采用

$query = "SELECT count(*) AS getCount from `auditsummary` where bizID=? AND statusID=?";

像往常一样获取值

$count = $row["getCount"];

这是我的方法:

$count = "SELECT * FROM yourtable WHERE x='x' and y='y'";

$result = $dbconn->prepare($count);
$result->execute();
$t_count = $result->rowCount();

echo $t_count;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM