2016-11-17 110 views
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 
+0

似乎你可以使用只需插入无批次 –

+0

我应该只使用插入?! – Ramya

+0

你可能会有阵列吗?删除所有'for'循环并且可以使用'insert_batch'。以及'$ data []'改变为'$ data' –

回答

0

请更改

for ($i = 1; $i < $this->input->post('customer_numrows'); $i++) 
{ 

$data[] = array(
      'product_id' => $temp, 
      'range'  => 0, 
      '[email protected]'  => 0, 
      'price'  => $this->input->post('customer_amount' . $i), 
      'uom'  => $this->input->post('customer_uom' . $i), 
      'usertype' => $customer 
      ); 
} 
$this->db->insert_batch('product_pricing', $data); 
} 

,而你使用$this->db->insert_batch('product_pricing', $data),所有值$data,它必须是数组,其密钥必须相同