Codeigniter - 插入批处理 - 具有相同名称的多个输入

时间:2016-11-21 06:57:21

标签: mysql codeigniter

我正在尝试为批发商,经销商和客户插入一批行 注意:我使用'append'来添加输入行,但是它们带有相同的输入名称。 我试图首先将它应用于批发,但它没有发生 当我向批发输入列表添加另一行时,它只占用一行(我的最后一行)输入,而我的另一行输入被丢弃。数组的var_dump显示了。

这是我的控制器文件

$range = $this->input->post('wrange1');
$usertype = $this->input->post('wusertype'); 
$uom = $this->input->post('wuom1'); 
$price = $this->input->post('wamount1'); //array of price
$vat = $this->input->post('wvat1'); 
var_dump($range);// i am getting only one output
$updateArray = [];
for($x = 0; $x < sizeof($price); $x++){
$updateArray[$x] = array(
    'product_id'=> $id,
    'range' => $range[$x],
    'usertype' => $usertype[$x],
    'uom' => $uom[$x],
    'price' => $price[$x],
    'vat' => $vat[$x]
);
}    
$this->productmodel->updatepricinglist($updateArray);  

这是我的模型文件:

public function updatepricinglist($updateArray)  {
 $this->db->insert_batch('product_pricing', $updateArray);
}

1 个答案:

答案 0 :(得分:1)

在循环中使用插入操作。如果你在所有字段中获得数组,那么你必须使用像for循环一样的索引数组,因为你说你在输出中只得到一个范围然后不使用循环中的索引数组。

$range = $this->input->post('wrange1');
$usertype = $this->input->post('wusertype'); 
$uom = $this->input->post('wuom1'); 
$price = $this->input->post('wamount1'); //array of price
$vat = $this->input->post('wvat1'); 
var_dump($range);// i am getting only one output

for($x = 0; $x < sizeof($price); $x++){
$updateArray = array(
    'product_id'=> $id,
    'range' => $range,
    'usertype' => $usertype[$x],
    'uom' => $uom[$x],
    'price' => $price[$x],
    'vat' => $vat[$x]
);
 $this->productmodel->updatepricinglist($updateArray);
}    
相关问题