doushi9474 2012-07-18 16:36
浏览 51
已采纳

每次更新到mysql的html表单数组

I have been racking my brains trying to figure this out for days and have come up short. I am trying to update rows in the database with the following form value:

<input type="text" name="item[]" maxlength="255" value="',htmlentities($item["item"]),'">
<input type="text" name="description[]" maxlength="255" value="',htmlentities($item["description"]),'">
<input type="text" name="rate[]" maxlength="10" value="',htmlentities($item["rate"]),'">
<input type="hidden" name="itemid[]" value="',htmlentities($item["id"]),'" />

This following array back:

Array
(
[item] => Array
    (
        [0] => item listing 1
        [1] => item listing 2
    )

[description] => Array
    (
        [0] => item testing description
        [1] => item testing description
    )

[rate] => Array
    (
        [0] => 1.00
        [1] => 2.00
    )

[itemid] => Array
    (
        [0] => 1
        [1] => 2
    )
)

Now im trying to update into a database with the following but to no avail I can only update the last row of fields (the [1] values) :( any help would be great

if (is_array($values))
{
for ($i = 0; $i < count($values); $i++)
{
    $item           = $values['item'];
    $description    = $values['description'];
    $rate           = $values['rate'];
    $id             = $values['itemid'];

    // $query = "UPDATE `invoice_items` SET `item` = '{$item}', `description` = '{$description}', `rate` = '{$rate}' WHERE `id` = '{$id}';";
    // Setting query function here
}
  • 写回答

2条回答 默认 最新

  • dqy92287 2012-07-18 16:40
    关注

    Add sub-array numbers too.

    if (is_array($values))
    {
    for ($i = 0; $i < count($values); $i++)
    {
        $item           = $values['item'][$i];
        $description    = $values['description'][$i];
        $rate           = $values['rate'][$i];
        $id             = $values['itemid'][$i];
    
        // $query = "UPDATE `invoice_items` SET `item` = '{$item}', `description` = '{$description}', `rate` = '{$rate}' WHERE `id` = '{$id}';";
        // Setting query function here
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制