Wednesday, 20 December 2017

How to perform a batch update using Codeigniter arrays?

How to perform a batch update using Codeigniter arrays?

ContentMiddleAd

ContentMiddleAd

You can create an array with all your option and then send it to the batch_update function.
$id = $this->input->post('idx'); //array of id
$desc = $this->input->post('itemdesc'); //array of item name
$qty = $this->input->post('qty'); //array or qty
$price = $this->input->post('price'); //array of price
$code = $this->input->post('codes'); // not array

$updateArray = array();

for($x = 0; $x < sizeof($id); $x++){

    $total[] = $price[$x] * $qty[$x];
    $updateArray[] = array(
        'poid'=>$id[$x],
        'item_desc' => $desc[$x],
        'item_qty' => $qty[$x],
        'price' => $price[$x],
        'total' => $total
    );
}      
$this->db->update_batch('po_order_details',$updateArray, 'poid'); 






No comments:

Post a Comment