Home > front end >  Call to undefined method CI_DB_mysqli_driver::groupBy()
Call to undefined method CI_DB_mysqli_driver::groupBy()

Time:12-19

I've created a web app using code igniter 3 to get data from 3 tables and display them in the view (quiz_table,question_table and answers_table). Below is the code in my controller,

    public function loadSingleQuizData_get()
{
    $quizId = $this->uri->segment(3);
    $this->load->model('QuizModel');
    $singleQuizQuestionData = $this->QuizModel->getSingleQuizQuestionDataFromDB($quizId);
    $data = array('singleQuizQuestionData' => $singleQuizQuestionData);
    print json_encode($data);
}

and below is the code in the model

function getSingleQuizQuestionDataFromDB($quizId)
{        //insert query
    try {
        $this->db->select('quiz_table.quizName');
        $this->db->select('quiz_table.creatorName');
        $this->db->select('quiz_table.rating');
        $this->db->select('question_table.questionId');
        $this->db->select('question_table.questionTitle');
        $this->db->select('question_table.correctAnswer');
        $this->db->select('answer_table.answer');
        $this->db->from('quiz_table');
        $this->db->where('quiz_table.quizId',$quizId);
        $this->db->join('question_table','question_table.quizId = quiz_table.quizId','INNER');
        $this->db->join('answer_table','answer_table.questionId= question_table.questionId','INNER');
        $this->db->from('quiz_table');
        $this->db->groupBy(['quiz_table.quizId', 'question_table.questionId']);
        $result = $this->db->get();


        $singleQuizQuestionData= $result->result_array();
        return $singleQuizQuestionData;
    } catch (Exception $e) {
        // log_message('error: ',$e->getMessage());
        return;
    }
}

When I try to load the results in the view I get the below error message enter image description here

Please help!

CodePudding user response:

https://codeigniter.com/userguide3/database/query_builder.html

The syntax for group by in codeigniter is group_by not groupBy (that would be laravel)

  • Related