php 非唯一表/别名:'测验表'

rpppsulh  于 2022-12-21  发布在  PHP
关注(0)|答案(1)|浏览(116)

我用code igniter 3创建了一个web应用程序,从3个表中获取数据并在视图中显示(quiz_table,question_table和answers_table)。下面是模型代码,

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->group_by(['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;
    }
}

当我尝试加载结果时,我得到以下错误x1c 0d1x
救命啊!

eeq64g8w

eeq64g8w1#

不允许在Codeigniter中使用多个from()子句。删除第二个from()将解决此问题

$this->db->from('quiz_table'); <---- here
$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');  <---- here
$this->db->group_by(['quiz_table.quizId', 'question_table.questionId']);

相关问题