我想计算 CodeIgniter 中的不同行...
我有一张这样的 table
NAME | ZIPCODE
Mike | 12345
Marc | 51233
TEST | 12345
现在我想要“2”的结果,因为有 2 个不同的邮政编码。
我尝试了很多,但没有得到这个:(
$this->db->select('zipcode, count(*)');
$getAll = $this->db->get('ads');
echo $getAll->num_rows();
但没有得到任何结果...我不知道我该如何做到这一点。 请帮忙
//编辑: 好吧,我找到了。抱歉提出问题。答案在这里
$this->db->distinct();
$this->db->select('zipcode');
$getAll = $this->db->get('ads');
echo $getAll->num_rows();
最佳答案
你可以使用这个:
$query = $this->db->query('select count(1) as x from your_table_name group by zipcode');
$row= $query->row();
$x = $row->x;
关于php - CodeIgniter MySQL 对不同行进行计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46844554/