繁体   English   中英

我在模型php codeigniter中的总和查询怎么了?

[英]what's wrong with my sum query in model php codeigniter?

这是我的模型代码:

function total($id)
    {
        $this->db->select_sum('score');
        $q = $this->db->get('my_table');
        $this->db->where('id',$id);
        $this->db->group_by('id');
        return $q->row()->score;  

    }  

为什么输出仍然将所有行加起来而不是ID的特定行?

$this->db->get()实际上运行查询。 您需要最后打电话。

function total($id)
    {
        $this->db->select_sum('score');
        $this->db->where('id',$id);
        $this->db->group_by('id');

        $q = $this->db->get('my_table');
        return $q->row()->score;  

    }  

暂无
暂无

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

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