gpt4 book ai didi

php - 更新 Codeigniter 中的批处理错误

转载 作者:行者123 更新时间:2023-11-29 08:23:52 25 4
gpt4 key购买 nike

我为我的数组创建了一个循环,然后接下来是更新批处理,但每当我尝试更新 1 项时,我的代码都不会更新。我无法发现我的错误在哪里。如何以简单的方式执行批量更新?

这是我的代码:

 /*THIS IS ALL ARRAY*/
$id = $this->input->post('idx');
$desc = $this->input->post('itemdesc');
$qty = $this->input->post('qty');
$price = $this->input->post('price');
$status = $this->input->post('status');

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[$x],
'status' => $status[$x]
);

$this->db->update_batch('po_order_details',$updateArray, 'poid'); //I guess poid is my error but im not sure. I think my array won't find the correct id for where.

}

这是我的数组示例输出:

   Array
(
[0] => Array
(
[poid] => 5
[item_desc] => Yakisoba
[item_qty] => 15
[price] => 40,000.00
[total] => 600
[status] => ACTIVE
)

[1] => Array
(
[poid] => 6
[item_desc] => Laptop
[item_qty] => 5
[price] => 15,000.00
[total] => 75
[status] => ACTIVE
)

[2] => Array
(
[poid] => 7
[item_desc] => Speaker
[item_qty] => 3
[price] => 5,000.00
[total] => 15
[status] => ACTIVE
)

[3] => Array
(
[poid] => 8
[item_desc] => Mouse
[item_qty] => 5
[price] => 500.00
[total] => 2500
[status] => ACTIVE
)

[4] => Array
(
[poid] => 9
[item_desc] => Keyboard
[item_qty] => 5
[price] => 1,000.00
[total] => 5
[status] => ACTIVE
)

)

以上就是我希望你们能帮助我的全部内容。

最佳答案

尝试将数组的每个值用单引号引起来,然后执行查询。我已经编辑了代码,将数组值括在单引号中。请尝试一下。这是编辑后的代码。

$updateArray[] = array(
'poid' => "'".$id[$x]."'",
'item_desc' => "'".$desc[$x]."'",
'item_qty' => "'".$qty[$x]."'",
'price' => "'".$price[$x]."'",
'total' => "'".$total[$x]."'",
'status' => "'".$status[$x]."'"
);

关于php - 更新 Codeigniter 中的批处理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18503294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com