简体   繁体   English

多插入行和表代码点火器

[英]multi insert row & table codeigniter

i have 1 form new customer, which will insert into 2 table('tbcust' & 'tbcp'). 我有1个新客户,它将插入2个表('tbcust'和'tbcp')。 I add button 'add new contact person' for insert row in table 'tcp', the button save in form will insert multiple table. 我在表“ tcp”中添加用于插入行的按钮“添加新联系人”,保存在表单中的按钮将插入多个表。 table 'tbcust' is ok, but row 'nama_pt' in table 'tbcp' just passing 1 character. 表'tbcust'可以,但是表'tbcp'中的行'nama_pt'仅传递1个字符。

CONTROLLER CONTROLLER

public function post_multiple_table(){

        $this->load->model('Multiple_model', 'multi_model', TRUE);
        $cust_input_data = array();
        //$cp_input_data = array();

        $cust_input_data['nama_pt'] = $this->input->post('nama_pt');
        $cust_input_data['tipe'] = $this->input->post('tipe');
        $cust_input_data['alamat'] = $this->input->post('alamat');
        $cust_input_data['email_cust'] = $this->input->post('email_cust');
        $cust_input_data['notelp'] = $this->input->post('notelp');
        $cust_input_data['nofax'] = $this->input->post('nofax');

        $this->form_validation->set_rules('nama_orang[]', 'nama_orang', 'required|trim|xss_clean');
        $this->form_validation->set_rules('nama_pt', 'nama_orang', 'required|trim|xss_clean');
        $this->form_validation->set_rules('nohp[]', 'nohp', 'required|trim|xss_clean');
        $this->form_validation->set_rules('email[]', 'email', 'required|trim|xss_clean');

        if ($this->form_validation->run() == FALSE){
         echo validation_errors(); // tampilkan apabila ada error
        }else{

        $nm = $this->input->post('nama_orang');
        $result = array();
        foreach($nm AS $key => $val){
        $result[] = array(
        "nama_orang"  => $_POST['nama_orang'][$key],
        "nama_pt"  => $_POST['nama_pt'][$key],
        "nohp"  => $_POST['nohp'][$key],
        "email"  => $_POST['email'][$key]
         );
        }

model 模型

public function create_multiple_tabel($nama_pt, $nama_orang){
        $this->db->insert('tbcust', $nama_pt);
        $this->db->insert_batch('tbcp', $nama_orang);
    }

and this the form & database 这是表格和数据库 TBCPtbcust形成新客户

如果您的行nama_pt长度设置为1 ,则在表tbcp nama_pt ,如果需要,将其设置为15或更大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM