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가 오름차순으로 정렬한다는 것입니다.
사용중인 프레임 워크를 모르지만 열의 순서는 중요하지 않습니다. 문제는 기본 키가 자동 증가하지 않는다는 것입니다. – Stijn
질문 제목을 앞으로 더 자세하게 설명하십시오. "PHP CodeIgniter"는 사람들이 실제로 검색하는 데 도움이되지 않습니다. –