active record summation in codeigniter

前端 未结 1 510
清歌不尽
清歌不尽 2021-01-15 16:07

I want to find sum of votes and am using codeigniter and mysql. In my votes table i\'ve a column which shows type of vote 0 for down vote and 1 for up vote how can i generat

相关标签:
1条回答
  • 2021-01-15 17:13

    That should do the trick:

    $this->db->select('SUM(type) as score');
    $this->db->where('question_id',1);
    $q=$this->db->get('votes');
    $row=$q->row();
    $score=$row->score
    

    Your $score variable now contains the sum of the types for that particular question.

    Hope that helps!

    0 讨论(0)
提交回复
热议问题