CodeIgniter Forums
CountVotes where ansid - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CountVotes where ansid (/showthread.php?tid=22468)



CountVotes where ansid - El Forum - 09-10-2009

[eluser]benfike[/eluser]
How can I count the votes number for a ansid?

Code:
votes_answer
*voteid
*ansid
*answer
votes_votes
*id
*ansid
*voteid
*userid

Thats my tables!

Code:
function countVotesByAnsId($id){
        $this->db->where('ansid', $id);
        $data = 0;
        $Q = $this->db->get('votes_votes');
        if($Q->num_rows() > 0){
            $data = $Q->num_rows();
        }
        $Q->free_result();
        return $data;
    }
But this dont work. :S I think this look the the VoteID because on the url-string 3 is the voteid.
http://www.arsenalfan.hu/szavazas/eredmeny/1 here you view the problem.

The total votes: 12

Something has 9 votes this true. But the "Valami" only has 3 votes and this write 9 again.

I hope you know what I speakBig Grin


CountVotes where ansid - El Forum - 09-10-2009

[eluser]jedd[/eluser]
I think your schema is .. sub-optimal. Can you describe it a bit better?

Also $this->db->count_all_results() is your friend.