我有一个表格,我将在数据库中迭代摩托车模型列表,其中空白字段用户将输入机箱和发动机型号。问题是当我提交表单时数据被复制到数据库中。有什么想法吗?
视图
for ($i = 1; $i <= $quantity; $i++) {
echo "<tr><input type='hidden' class='input-xlarge' name='order_id[]' id='id' value='$order_id'>
<td class='text-center'><input type='hidden' class='input-xlarge' name='model[]' id='model' value='$row->model'>$row->model</td>
<td class='text-center'><input type='hidden' class='input-xlarge' name='color[]' id='color' value='$row->color'>$row->color</td>
<td class='text-center'><input type='hidden' class='input-xlarge' name='quantity[]' id='quantity' value='1'>1</td>
<input type='hidden' class='input-xlarge' name='quantity_received[]' id='quantity_received' value='1'>
<td class='text-right'><input type='text' class='input-xlarge' name='engine_no[]' id='engine_no' value='$engine_no' placeholder='Engine No'></td>
<td class='text-right'><input type='text' class='input-xlarge' name='chassis_no[]' id='chassis_no' value='$chassis_no' placeholder='Chassis No'></td>
</td>
<td class='text-right'><input type='text' class='input-xlarge' name='promo[]' id='promo' value='$promo'></td>
<input type='hidden' class='input-xlarge' name='unit_cost[]' id='unit_cost' value='$unit_cost'>
</tr>";
}
控制器
$this->load->model('purchase_order');
#Batch insert
$order_id = $this->input->post("order_id");
$model = $this->input->post("model");
$color = $this->input->post("color");
$quantity = $this->input->post("quantity");
$quantity_received = $this->input->post("quantity_received");
$engine_no = $this->input->post("engine_no");
$chassis_no = $this->input->post("chassis_no");
$promo = $this->input->post("promo");
$remarks = $this->input->post("remarks");
$code = $this->input->post("code");
$receiving_date = $this->input->post("receiving_date");
$purchase_order_no = $this->input->post("purchase_order_no");
$branch_code = $this->input->post("branch_code");
$unit_cost = $this->input->post("unit_cost");
$supplier_name = $this->input->post("supplier_name");
foreach ( $quantity as $key=>$value )
{
$insertOrders[] = array( 'id'=>null,
'purchase_order_no'=>$purchase_order_no,
'branch_code'=>$branch_code,
'order_id'=>$order_id[$key],
'model'=>$model[$key],
'color'=>$color[$key],
'quantity'=>$quantity[$key],
'quantity_received'=>$quantity_received[$key],
'engine_no'=>$engine_no[$key],
'chassis_no'=>$chassis_no[$key],
'promo'=>$promo[$key],
'remarks'=>$remarks,
'code'=>$code,
'receiving_date'=>$receiving_date,
'date_received'=>$receiving_date,
'invoiceDRNo'=>$invoiceDRNo,
'waybillNo'=>$waybillNo,
'unit_cost'=>$unit_cost[$key],
'supplier_name'=>$supplier_name,
'In'=>'IN'
);
}
# Batch update
$result1 = $this->purchase_order->BatchInsertOrders1($insertOrders);
模型
public function BatchInsertOrders1($insertOrders){
$this->db->insert_batch('purchase_order_qty', $insertOrders);
$result = array();
$result['error'] = $this->db->_error_number();
$result['message'] = $this->db->_error_message();
return $result;
}