Php codeigniter中的活动记录求和
我想找到投票总数,我正在使用和mysql。在我的投票表中,有一列显示了投票类型,0表示反对票,1表示赞成票。我如何生成这样的sqlPhp codeigniter中的活动记录求和,php,mysql,codeigniter,Php,Mysql,Codeigniter,我想找到投票总数,我正在使用和mysql。在我的投票表中,有一列显示了投票类型,0表示反对票,1表示赞成票。我如何生成这样的sql SELECT sum(type) FROM `votes` WHERE questions_id=1 使用codeigniter数据库类 干杯应该可以做到这一点: $this->db->select('SUM(type) as score'); $this->db->where('question_id',1); $q=$this->
SELECT sum(type) FROM `votes` WHERE questions_id=1
使用codeigniter数据库类
干杯应该可以做到这一点:
$this->db->select('SUM(type) as score');
$this->db->where('question_id',1);
$q=$this->db->get('votes');
$row=$q->row();
$score=$row->score
您的$score
变量现在包含该特定问题的类型的总和
希望有帮助