0

在下面的代码中,这是一个考试课程表,有 2 列在下拉考试名称和课程代码中。我的目标是当我选择课程代码时,它应该从课程主题表中获取相关值主题代码,并从主题主表中获取主题代码的相关主题名称,并添加到课程详细信息表中。

我试过当我添加考试名称和课程代码时,它被添加到考试课程和课程详细信息表(即课程代码)课程代码被添加到课程详细信息表中。请任何人帮助我。

考试课程

考试名称| 课程代码

课程科目

课程代码 |科目代码

学科硕士

主题代码 | 主题名称

课程详情

课程代码 | 主题代码 | 主题名

   Controller examcourse_site

function index()
    {   
        if($query = $this->examcourse_model->get_records())
        {
            $data['exam_records'] = $query;
        }
        //to display data form another table and append in this table examcourse
        if($query = $this->examcourse_model->get_exam_table_records())
        {
            $data['examname_records'] = $query;
        }
            //to display data form another table and append in this table examcourse        
        if($query = $this->examcourse_model->get_course_code_records())
        {
            $data['course_records'] = $query;
        }
        $this->load->view('examcourse_view', $data);
    }
    function create()
    {
        $j=1;
        $createcustomer = $this->input->post('createcustomer');
        if( $this->input->post('createcustomer') != false ){
        foreach ($createcustomer as $j)
        {
        $data = array(
            'exam_name' => $this->input->post('exam_name_id'.$j),
            'course_code' => $this->input->post('course_code_id'.$j)
        );

        //$course_code= mysql_real_escape_string($_POST["course_code_id".$j]);
        $exam_name = $this->input->post('exam_name_id'.$j);
        if ($exam_name != ""){
            $this->examcourse_model->add_record($data, $exam_name);
        }
        $j++;   
        }
    }
    $this->index();
    }

模型:

    function get_records()
    {
        $query = $this->db->get('examcourse');
        return $query->result();    
    }
    function add_record($data)
    {
        $this->db->insert('examcourse', $data);
        $this->db->insert('course_table', $data);
        return ;
    }
    function get_exam_table_records()
    {
        $this->db->select("CONCAT(exam_name, ' ', month,' ',year) AS fullexamname", FALSE);//this will concat the value
        $query = $this->db->get('exam_table');
        return $query->result();
    }
    //to get the record from coursemaster table
    function get_course_code_records()
    {
        $query = $this->db->get('coursemaster');
        return $query->result();    
    }
4

0 回答 0