1
public function insertpricinglist()
{
$wholesale = "wholesale";
$dealer = "dealer";
$customer = "customer";
$query = $this->db->get_where('products', array('productname' => $this->input->post('productname')));
$row = $query->result();
$temp = $row->id;
for ($i = 1; $i < $this->input->post('numrows'); $i++)
{
$data[] = array(
'product_id' => $temp,
'range' => $this->input->post('range' . $i),
'[email protected]' => $this->input->post('vat' . $i),
'price' => $this->input->post('amount' . $i),
'uom' => $this->input->post('uom' . $i),
'usertype' => $wholesale
);
}
$this->db->insert_batch('product_pricing', $data);
for ($i = 1; $i < $this->input->post('dealer_numrows'); $i++)
{
$data[] = array(
'product_id' => $temp,
'range' => $this->input->post('dealerrange' . $i),
'[email protected]' => $this->input->post('dealervat' . $i),
'price' => $this->input->post('dealeramount' . $i),
'uom' => $this->input->post('dealeruom' . $i),
'usertype' => $dealer
);
}
$this->db->insert_batch('product_pricing', $data);
for ($i = 1; $i < $this->input->post('customer_numrows'); $i++)
{
$data[] = array(
'product_id' => $temp,
'price' => $this->input->post('customer_amount' . $i),
'uom' => $this->input->post('customer_uom' . $i),
'usertype' => $customer
);
}
$this->db->insert_batch('product_pricing', $data);
}
我在嘗試插入我的一批數據時出現錯誤。我試圖插入產品定價表中批量批次和批發商批次和客戶批次項目插入相同的產品ID。Codeigniter - 插入批處理 - 我的sql
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Array' at line 1
// 嚴重性:注意
Message: Trying to get property of non-object
Filename: models/productmodel.php
Line Number: 24
Backtrace:
File: E:\wamp\www\CodeIgniter\application\models\productmodel.php
Line: 24
Function: _error_handler
似乎你可以使用只需插入無批次 –
我應該只使用插入?! – Ramya
你可能會有陣列嗎?刪除所有'for'循環並且可以使用'insert_batch'。以及'$ data []'改變爲'$ data' –