简体   繁体   English

使用更新批处理对Codeigniter进行多次更新

[英]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 遇到PHP错误严重性:注意

Message: Undefined index: id 消息:未定义的索引:id

Filename: database/DB_query_builder.php 文件名:database / DB_query_builder.php

Line Number: 1955 线路编号:1955

Backtrace: 回溯:

File: E:\\xampp\\htdocs\\restly\\application\\controllers\\admin.php Line: 343 Function: update_batch 文件:E:\\ xampp \\ htdocs \\ restly \\ application \\ controllers \\ admin.php行:343功能:update_batch

File: E:\\xampp\\htdocs\\restly\\index.php Line: 315 Function: require_once 文件:E:\\ xampp \\ htdocs \\ restly \\ index.php行:315功能: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应该是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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