我的以下模型是用於在db中插入數組。我也提交了查看文件的例子。請幫忙用循環在codeigniter中插入批處理數據。Codeigniter中的數組插入錯誤
class Purchase_model extends CI_Model{
public function purchase(){
$price = $this->input->post('price');
$quantity = $this->input->post('quantity');
$date = $this->input->post('date');
$vendor_name = $this->input->post('vendor_name');
$model = $this->input->post('model');
$invoice_no = $this->input->post('invoice');
$temp = count($this->input->post('vendor_name'));
for($i=0; $i<$temp; $i++){
$data = array(
'date'=>$date[$i],
'vendor_name'=>$vendor_name[$i],
'model'=>$model[$i],
'price' =>$price[$i],
'purchase_quantity'=>$quantity[$i],
'amount' =>$price[$i]*$quantity[$i],
'invoice_no'=>$invoice_no[$i]
);
$insert = $this->db->insert('purchase',$data);
return $insert; }
}
但是,當我提出我得到分貝以下值
Sl date Vendor name model price quantity amount invoice
89 2 A 1 0 0 a
請幫助。 我需要在db中使用一種形式插入多個值。
我的看法形式的樣子
<?php
$data = array ('name' => 'quantity',
'class' =>'input-xlarge',
'value' => set_value('quantity')
);
?>
<?php echo form_input ($data); ?>
我控制器
public function purchase()
{
if($this->Purchase_model->purchase()){
$this->session->set_flashdata('Success', 'You are entered data successfully');
redirect('home/purchase_form');
}
}
請出示您的控制器代碼如果可能的話.. – 2014-09-26 05:02:46
公共職能購(){ \t \t \t if($ this-> Purchase_model-> purchase()){ \t \t \t \t \t $ this-> session-> set_flashdata('Success','您輸入的數據成功'); \t \t \t \t \t redirect('home/purchase_form'); \t \t \t \t \t} } – user3752230 2014-09-26 05:15:00
編輯您的問題並顯示完整查看代碼它只是您顯示的單個元素。 – 2014-09-26 05:21:40