为什么这个代码不起作用?你能帮我吗


why this code not work? can you help me?

为什么此代码不起作用?

我的型号

 public function get_question_by_testid($id) {
    $this->db->select('question, description, name');
    $this->db->from('question');
    $this->db->join('test', 'test.id = question.testid');
    $this->db->where('testid', $id);
    $query = $this->db->get();
    $result = $query->result_array();
    $count = count($result);
    if (empty($count) || $count > 1) {
        $question = null;
        return $question;
    } else {
        return $result;
    }
}

为什么这个代码不起作用?

 //controller function test($id = NULL) {
    $data['tests'] = $this->student_model->get_test_by_id($id);
    $data['questions'] = $this->student_model->get_question_by_testid($id);
    $this->load->view('studentExam',$data);
}   

为什么这个代码不起作用?

//view
foreach ($tests as $test)
{
    echo $test['name'];
    echo '</br>';
    echo $test['description'];
 }
 foreach ($questions as $question) {
     echo $question['test'];
     echo $question['question'];
     echo '</br>';
 }  

您必须更改此行:

$this->db->where('testid', $id);

对此:

$this->db->where('question.testid', $id);