我对 Codeigniter 的 insert_batch 模型函数有疑问,它似乎重新排列了以升序方式传递给它的数组。这是我的代码
控制器(获取所有发布数据并将其排列成数组):
$product_id = $this->input->post('product_id');
$colors = $this->input->post('color_name');
$quantity = $this->input->post('product_quantity');
$payment_option = $this->input->post('payment_option');
$price = $this->input->post('product_price');
$date = date('Y-m-d');
$orders = array();
$other_info = $this->business_mgmt->unique_details();
for($i = 0; $i < count($product_id); $i++) {
$color_id = $this->products_model->select_color_id($colors[$i]);
$orders[] = array(
'order_id' => null,
'invoice_number' => $other_info[0],
'customer_number' => $other_info[1],
'user_id' => 1,
'product_id' => $product_id[$i],
'color_id' => $color_id,
'quantity' => $quantity[$i],
'price' => $price[$i],
'order_date' => $date
);
}
$this->business_mgmt->insert_order($orders);
这是模型:
function insert_order($order_details) {
$this->db->insert_batch('exp_mcc_orders', $order_details);
print '<pre>';
print_r($order_details);
print '</pre>';
}
这是错误消息:
Error Number: 1062
Duplicate entry '0' for key 'PRIMARY'
INSERT INTO `exp_mcc_orders`
(`color_id`, `customer_number`, `invoice_number`,`order_date`, `order_id`, `price`,
`product_id`, `quantity`, `user_id`)
VALUES ('2','260','20130876617','2013-08-27',NULL,'15','4','4',1)
Filename: C:\xampp\htdocs\MiracleCandleCompany\website\system\database\DB_driver.php
行号:330
提前谢谢。我的数据库中列的正确顺序是我在阵列上使用的顺序。问题是codeigniter以升序重新排列它。