【发布时间】:2017-04-01 00:44:54
【问题描述】:
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 ),
'vat@' => $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 ),
'vat@' => $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。
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
【问题讨论】:
-
看来你可以只使用 Insert without batch
-
我应该只使用插入吗?!
-
你有多少个数组?删除所有
for循环并可以使用insert_batch。以及$data[]更改为$data -
但我必须在我的表中的“用户类型”列中插入第一批的“批发”和第二批的“经销商”和第三批的“客户”
-
使用 3 个 diff 数组,例如
$usertype、$wholesale和$dealer...
标签: mysql codeigniter