当前位置:  开发笔记 > 编程语言 > 正文

某些字段上的PHP Codeigniter批量更新失败

如何解决《某些字段上的PHPCodeigniter批量更新失败》经验,为你挑选了0个好方法。

我在这个html上有一个表: VIEW

NO TYPE ITEM DAMAGE REPAIR REMARKS MANHOUR MATERIAL A / C

JQUERY 我使用这个jquery获得了那些表上的所有值:

$('#tableReport').find('tbody').find('tr').each(function () {
        var row_data = [];
        $(':input', this).each(function () {
            row_data.push($(this).val());
        });
        table_data.push(row_data);
 });

结果看起来像这样:

Array
(
[0] => Array
    (
        [0] => 68
        [1] => Cleaning
        [2] => Certificate
        [3] => Broken
        [4] => Blast&Paint
        [5] => AAAAAA
        [6] => 10.00
        [7] => a
        [8] => b
    )

[1] => Array
    (
        [0] => 69
        [1] => Cleaning
        [2] => Exterior
        [3] => Modified
        [4] => Replace
        [5] => BBBBB
        [6] => 10.00
        [7] => c
        [8] => d
    )

)

这个数组用于我表中的update_batch.

mysql> select * from tb_repair_detail;
+-----------+--------------------+------+-----------+-----------+---------+---------+----------+------+
| DETAIL_ID | REPAIR_ESTIMATE_ID | ITEM | DAMAGE_ID | REPAIR_ID | REMARKS | MANHOUR | MATERIAL | AC   |
+-----------+--------------------+------+-----------+-----------+---------+---------+----------+------+
|        68 |                 43 | 01   | 01        | 30        | AAAAAA  |   10.00 |     NULL | NULL |
|        69 |                 43 | 03   | 16        | 45        | BBBBB   |   10.00 |     NULL | NULL |
+-----------+--------------------+------+-----------+-----------+---------+---------+----------+------+
2 rows in set (0.00 sec)

SO,AJAX调用控制器采取这个动作:

$.ajax({
        url: "",
        type: "POST",
        data: {
            POST_ARRAY: table_data
        },
        dataType: 'json',
        success: function (obj) {
            console.log(obj);
        }
    });
return false;

CONTROLLER

public function update_json_detail(){
   $execute = $this->input->post("POST_ARRAY");
   /*CODE TO INSERT BATCH*/
   $callback = $this->m_admin->update_eir_to_cost($execute, execute_first_index[0]);
}

这是模型.

public function update_eir_to_cost($data, $id) {
    $this->db->trans_start();
    $this->db->update_batch('tb_repair_detail', $data, $id); 
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE) {
        // generate an error... or use the log_message() function to log your error
        echo "Error Updating";
    }
}

我的大问题是,我想使用更新批处理.但是,我只想更新manhour和ac字段.我真的坚持了好几天,任何帮助它如此欣赏

更新 谢谢Mr.Sultan先生.现在,我的代码看起来像这样:

public function update_json_detail() {
    $post_data = $this->input->post("POST_ARRAY");
    $execute = array();
    foreach ($post_data as $data) {
        $execute[] = array(
            'ID'=> $data['0'],
            'MATERIAL' => $data['7'],
            'AC' => $data['8']
        );
    }

    /* CODE TO INSERT BATCH */
    $callback = $this->m_admin->update_eir_to_cost($execute);
}

我的模型有点麻烦,因为我需要三个参数来update_batch

public function update_eir_to_cost($id, $material, $ac) {
    $data = array(
        "MATERIAL" => $material,
        "AC" => $ac
    );

    $this->db->trans_start();
    $this->db->where($id);
    $this->db->update_batch('tb_repair_detail', $data);
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE) {
        // generate an error... or use the log_message() function to log your error
        echo "Error Updating";
    }
}

谢谢你的解决方案

推荐阅读
路人甲
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有