php - 如何在php中执行多个计数查询

标签 php mysql count

我从一张表中执行了 4 次计数查询。但我从所有查询中得到相同的输出。但实际值与表中不同。

这是我的 table 。

ID ||  notify_type     ||  status
__________________________________________

1  || resume_uploaded  ||    1

这是我的疑问:

$notify_query1 = "select count(*) from notify where status = 1 and notify_type = 'resume_uploaded'";
$row1 = mysqli_query($db_manager->connection,$notify_query1);
$rcount = mysqli_num_rows($row1);

$notify_query2 = "select count(*) from notify where status = 1 and  notify_type = 'detail_filled'";
$row2 = mysqli_query($db_manager->connection,$notify_query2);
$dcount = mysqli_num_rows($row2);

$notify_query3 = "select count(*) from notify where status = 1 and notify_type = 'job_detailed'";
$row3 = mysqli_query($db_manager->connection,$notify_query3);
$jcount = mysqli_num_rows($row3);

$notify_query4 = "select count(*) from notify where status = 1 and notify_type = 'msg_sent'";
$row4 = mysqli_query($db_manager->connection,$notify_query4);
$mcount = mysqli_num_rows($row4);

我从所有四个查询中获取输出1: 请帮助我。

最佳答案

使用fetch_row()而是 mysqli_num_rows()

$result = $db->query("select count(*) from notify where status = 1 and notify_type = 'resume_uploaded'");
$row = $result->fetch_row();
echo 'No of count: '. $row[0];

关于php - 如何在php中执行多个计数查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34504986/

相关文章:

php - PHP 中的命令行进度条

php - 测试遗留 PHP 意大利面条代码?

php - 阻止通过 PHP 进行远程访问

stdin - PHP CLI 中的 STDIN 非阻塞

mysql - 查询优化

cakePHP - 如何获取相关模型的项目数?

python - 分组并计算唯一值的数量( Pandas )

java - 连接到Mysql

php - 用 PHP 中的变量文本替换确切的变量字符串?

php - 从 MySQL 中的两个连接表中获取多个计数