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 怎样采集或者其它途径拿到全国最新个体工商户数据
  • ¥20 我是一名大学生,想学习java是自学还是报培训班呢
  • ¥15 pycharm该如何爬取网易云歌曲下的评论?
  • ¥15 java调用sap webservice问题
  • ¥20 如何完全复现何恺明resnet论文里的结果,有代码吗,获得论文中的结果(如下图)
  • ¥15 mysql如果表行行数小于1000条还需要分区吗
  • ¥20 有关matlab自定义特殊算符的问题
  • ¥15 第15届蓝桥杯选拔赛斗鱼养殖场
  • ¥15 在vivado的FIFO使用中,FIFO有没有提供可以输出内部存储空间状态的端口?
  • ¥15 C++ QT内存数据匹配对比指导