gpt4 book ai didi

php - 在 Codeigniter 中统计通过 distinct() 或 group_by() 过滤的结果

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:08:58 25 4
gpt4 key购买 nike

我想用 CI(使用 postgreSQL)统计我的事件记录查询结果。我正在使用 count_all_results(),它适用于大多数查询,但在加入后使用 distinct()group_by() 时就不行了,因为 count_all_results() 忽略了这些函数。

这是一个修复程序,尚未在最新的 (2.1.3) 稳定版本中实现。 https://github.com/EllisLab/CodeIgniter/commit/b05f506daba5dc954fc8bcae76b4a5f97a7433c1

当我自己尝试在当前版本中实现此修复时,没有完成额外的过滤。行数保持不变。

关于如何在当前版本中实现这一点的任何提示,或其他计算由 distinct()group_by() 过滤的结果的方法?

最佳答案

    $this->db->select('COUNT(id)');
$this->db->join();
$this->db->distinct();
$this->db->group_by();
//...etc ...
$query = $this->db->get('mytable');

return count($query->result());

    $this->db->join();
$this->db->distinct();
$this->db->group_by();
//...etc ...
$query = $this->db->get('mytable');

return $query->num_rows();

关于php - 在 Codeigniter 中统计通过 distinct() 或 group_by() 过滤的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16379046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com