0
我想制作发票表单。为此,我需要一次插入多个数据。例如我想一次输入db 5类别的销售或购买产品。但我对insert_batch不感兴趣。我尝试,但我在数据库中有一些空值。codeigniter数组和循环插入多个数据
我的型号是:
<?php
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<10; $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; }
}}
我的控制器:
public function purchase(){
if($this->Purchase_model->purchase()){
$this->session->set_flashdata('Success',
'You are entered data successfully');
redirect('home/purchase_form');
}
}
我的例如观点:
<?php echo form_label ('Price:'); ?>
<select name="price[]" id="price" class="input-xlarge">
</select>
<?php echo form_label ('Quantity'); ?>
<?php
$data = array ('name' =>'quantity[]',
'class' =>'input-xlarge',
'value' => set_value('quantity')); ?>
<?php echo form_input ($data); ?>
<?php echo form_label ('Price:'); ?>
<select name="price[]" id="price2" class="input-xlarge">
</select>
<?php echo form_label ('Quantity'); ?>
<?php
$data = array ('name' =>'quantity[]',
'class' =>'input-xlarge',
'value' => set_value('quantity')); ?>
<?php echo form_input ($data); ?>
请帮助。
你会得到哪些值为空?请明确说明 ! – Hatem 2014-10-02 03:35:17
供应商数量 – user3752230 2014-10-02 06:41:09
您的视图中没有“供应商”元素!请显示您的视图层的完整脚本! – Hatem 2014-10-02 14:05:33