Sam*_*son 2 php mysql codeigniter
我想找到总票数,并使用codeigniter和mysql.在我的投票表中,我有一个列显示投票类型为0表示向下投票,1表示向上投票如何生成一个看起来像这样的sql
SELECT sum(type) FROM `votes` WHERE questions_id=1
Run Code Online (Sandbox Code Playgroud)
使用codeigniter数据库类
干杯
jfo*_*her 12
这应该够了吧:
$this->db->select('SUM(type) as score');
$this->db->where('question_id',1);
$q=$this->db->get('votes');
$row=$q->row();
$score=$row->score
Run Code Online (Sandbox Code Playgroud)
您的$score变量现在包含该type特定问题的s 的总和.
希望有所帮助!