Take the 2-minute tour ×

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 generate an sql that looks like this

SELECT sum(type) FROM `votes` WHERE questions_id=1

using codeigniter database class


share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

That should do the trick:

$this->db->select('SUM(type) as score');

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

Hope that helps!

share|improve this answer
thanx so much, it works fine now. –  samdev Feb 23 '11 at 0:48
add comment

Your Answer


