KrotovRoman
6/26/2018 - 11:11 AM

Посчитать количество повторений в БД (рейтинг голоса)

подсчитать за какой файл больше всего проголосовали

public function get_winner_opros($id_opros) {
        $this->db->limit(1);
        $this->db->select('id_file, count(*) as count');
        $this->db->group_by('id_file');
        $this->db->order_by('count', 'desc');
        $this->db->where('id_opros', $id_opros);
        $files_votes = $this->db->get('files_votes');
        if ($files_votes->num_rows() <= 0) {
            return FALSE;
        }
        return $files_votes->row()->id_file;
    }