[英]what's wrong with my sum query in model php codeigniter?
here's my model code : 这是我的模型代码:
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;
}
why the output still sum all of row not the specific row with id? 为什么输出仍然将所有行加起来而不是ID的特定行?
$this->db->get()
actually runs the query. $this->db->get()
实际上运行查询。 You need to call that last. 您需要最后打电话。
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.