得到mysql中的id计数

时间:2018-06-06 06:51:37

标签: php mysql

enter image description here

我想计算所有针对id的条目

我使用了这个查询

select count(*) from table1 group by `id`
问题是我的表有3条记录

id A   has 2 records
id B   has 1 record

当我使用php运行此查询时,它给了我2个输入

 $mysqli = new mysqli("localhost","root", "", "db");

     $query = $mysqli->prepare("SELECT COUNT(*) FROM `tble1` GROUP by `ID`");

$query->execute();
$query->store_result();

$rowsaff = $query->num_rows;

echo $rowsaff;

1 个答案:

答案 0 :(得分:0)

编辑:误解了这个问题。

您必须选择不同ID的计数:

 $query = $mysqli->prepare("SELECT COUNT(distinct `ID`) FROM `tble1`");