douseda0009 2013-01-31 16:40
浏览 41
已采纳

在Codeigniter中管理动态表单并更新数据库?

I have a database with a number of tables, dbtable.

I'm creating a form with php and I layout the form using <table>.

Each <tr> in the table corresponds to one row in a dbtable.

So, the more rows in a dbtable, the more tr-tags.. you get it.

My question is:

How should I name the input-tags to be able to use the POST-variables to update the database accordingly?

At the moment, I'm naming them 1_name, 2_name, 3_name for one dbtable data then 1_1_valueA, 1_1_valueB, 1_2_valueA, 1_2_valueB for data that belongs to 1_name, 2_name etc.

But I feel this is not such a good approach..

  • 写回答

2条回答 默认 最新

  • dsf4s5787 2013-01-31 16:48
    关注

    name them like this:

    item[0][db_row_id]
    item[0][value_a]
    item[0][value_b]
    
    item[1][db_row_id]
    item[1][value_a]
    item[1][value_b]
    

    where the numbers 0 and 1 etc are just assigned as indicies in a POST array

    you will be able to retrieve all of the items with $_POST['item']

    or in CI $this->input->post('item')

    and it will look like this:

    array(
     array('db_row_id'=>val,'value_a'=>val,'value_b'=>val),
     array('db_row_id'=>val,'value_a'=>val,'value_b'=>val)
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵