2016-11-21 18 views
0

卸売業者のディーラーと顧客のための行のバッチを挿入しようとしています 注:私は入力の行を追加するのに「append」を使っていますが、 。 私は卸売にこれを最初に適用しようとしていますが、それは起こっていません 私は卸売入力リストに1行(私の最後の行)の入力と私の他の行を取っている別の行を捨てるときに別の行を追加します。配列のvar_dumpはそれを明らかにする。Codeigniter - バッチを挿入する - 同じ名前の複数の入力

これは、これは私のモデルファイルである私のコントローラファイル

$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

loop.andのための内部利用の挿入操作forループのようなインデックスの配列を使用してください。出力で1つの範囲しか得られなかったので、ループの中でインデックスの配列を使用しないでください。

$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); 
}  
+0

私の配列$範囲を使用すると、複数のように範囲を持つようにしたいと同じ名前 – Ramya

+0

@Ramyaを持つすべての入力フィールドを取得していませんか?入力を配列名[]として使用する必要があります。あなたが価格でしたように。 –

+0

ええ、私は同じ名前の入力値の配列を格納しようとしているときに起こっていない!私のコードで、var_dump()の配列変数と同じように、同じ名前の最後の入力を表示しています!だから、私は各入力名にIDを追加しようとしましたが、それは私がそれを作った長いプロセスが働いた! – Ramya

関連する問題