简体   繁体   English

在codeigniter中插入批处理选项

[英]insert batch option in codeigniter

I can use insert batch in codeigniter but my problem is if I have 7 field in my form and i fill up 5 field in the form and submit I get 7 row in db. 我可以在codeigniter中使用插入批处理,但是我的问题是如果我的表单中有7个字段,并且我填写了表单中的5个字段并提交,我在db中得到了7行。 5 row is ok but others 2row show sl no, date and invoice no. 5行可以,但其他2行则显示sl no,日期和发票编号。 I want only 5 data which is fill up by form not others. 我只需要5个数据,而不是其他数据。 my model is 我的模特是

public function purchase(){  
  $data = array(
    array(
     'date'=> $this->input->post('date'),
     'vendor_name'=>$this->input->post('vendor_name'),
     'model'=>$this->input->post('model'),
     'price' =>$this->input->post('price'), 
     'purchase_quantity'=>$this->input->post('quantity'),
     'amount'  =>$this->input->post('price')*$this->input->post('quantity'),
     'invoice_no'=>$this->input->post('invoice')
     ),
      array(
     'date'=> $this->input->post('date'),
     'vendor_name'=>$this->input->post('vendor_name2'),
     'model'=>$this->input->post('model2'),
     'price' =>$this->input->post('price2'), 
     'purchase_quantity'=>$this->input->post('quantity2'),
     'amount'  =>$this->input->post('price2')*$this->input->post('quantity2'),
     'invoice_no'=>$this->input->post('invoice')
     ),

      array(
     'date'=> $this->input->post('date'),
     'vendor_name'=>$this->input->post('vendor_name3'),
     'model'=>$this->input->post('model3'),
     'price' =>$this->input->post('price3'), 
     'purchase_quantity'=>$this->input->post('quantity3'),
    'amount'  =>$this->input->post('price3')*$this->input->post('quantity3'),
     'invoice_no'=>$this->input->post('invoice')
     )
     );
    $insert = $this->db->insert_batch('purchase',$data);
   return $insert; 
  }

Please help 请帮忙

you can use simple insert query on foreach 您可以在foreach上使用简单的插入查询

foreach ($data as $row){
$insert = $this->db->insert('purchase',$row);

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

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