简体   繁体   中英

multiple update on codeigniter with update batch

$ID = $this->input->post('barang');
$reslt = array();
foreach($ID AS $key => $val){
    $reslt[] = array(
    "id" => $ID[$key],
    "stok"  => $_POST['qty'][$key]);
}

$this->db->update_batch('barang', $reslt, 'id');

Error

A PHP Error was encountered Severity: Notice

Message: Undefined index: id

Filename: database/DB_query_builder.php

Line Number: 1955

Backtrace:

File: E:\\xampp\\htdocs\\restly\\application\\controllers\\admin.php Line: 343 Function: update_batch

File: E:\\xampp\\htdocs\\restly\\index.php Line: 315 Function: require_once

Can any body help me?

You have added semicolon extra,just remove that. Updated code:

$reslt[] = array(
                    "id" => $ID[$key],
                    "stok"  => $_POST['qty'][$key])
}

Try this code :

$ID = $this->input->post('barang');
    $reslt = array();
    for($x = 0; $x < sizeof($ID); $x++){
        {
            $reslt[] = array(
                        "id" => $ID[$x],
                        "stok"  => $_POST['qty'][$x]
                        );
        }
    $this->db->update_batch('barang', $reslt, 'id');

Update this code into your code ..and check it and accept if it works!

You have typo error here

$_POST['qty'][$key]);

Change this to

$_POST['qty'][$key])

Your Final foreach should be:

foreach($ID AS $key => $val){
$reslt[] = array(
    "id"    => $ID[$key],
    "stok"  => $_POST['qty'][$key])
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM