0

表格1:subjectmaster

id | subjectcode | subjectname
------------------------------
1  | phy         | physics

表2:course master

id | coursecode | coursename
----------------------------
1  | bsc        | bachlore of science

表3:examcourse

id | examname | course_code
---------------------------
1 | semester  | bsc

表4:course_table

id | coursecode | coursename |  subjectcode | subjectname | examname
--------------------------------------------------------------------

模型:

function add_record($data)
{
    $this->db->insert('examcourse', $data);
    $this->db->insert('course_table', $data);
    return;
}

控制器:

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();
    }

如果我单击插入表单,它只插入coursecodeexamnametable3table4
中 ,但我需要在table4coursecode中插入, coursename, subjectcode, subjectname, 。examname

如何获取值并将它们插入表中?

4

2 回答 2

0

您的$data数组应该将键作为course_table

$data=array(
'coursecode'=>'test',
'coursename'=>'test',
'subjectcode'=>'test,'
'subjectname'=>'test',
'examname'=>'test'
);

$this->db->insert('course_table', $data);

只需确保您$data使用正确的值和键创建数组

于 2013-08-27T10:05:53.943 回答
0

试试这个:
从这样的检索值data array

<?php
    function add_record($data)
    {
        $temp   = array('coursecode'=>$data['coursecode'], 
                    'coursename'=>$data['coursename'],
                    'subjectcode'=>$data['subjectcode'],
                    'subjectname'=>$data['subjectname'],
                    'examname'=>$data['examname']
                    );
        $this->db->insert('course_table', $temp);
        $this->db->insert('examcourse', $data);
        $this->db->insert('course_table', $data);
        return;
    }
?>
于 2013-08-27T10:23:23.943 回答