2016-11-17 3 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); 
} 

Я получаю сообщение об ошибке при попытке вставить мою партию данных. Я пытаюсь вставить в таблицу ценообразования продукта, в которую вставляются партии партии и партии партии партии и дилеров с одинаковым идентификатором продукта.Codeigniter - insert batch - my 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 []' change like '$ 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, он должен быть массив, ключи должны быть то же самое