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 关于vmprotect3.8.4虚拟文件一项
  • ¥20 C#调用虚拟键盘TabTip.exe
  • ¥15 Qt4代码实现下面的界面
  • ¥15 CCS离散化传递函数与仿真不一致
  • ¥15 prism提示我reinstall prism 如何解决
  • ¥15 asp.core 权限控制怎么做,需要控制到每个方法
  • ¥20 while循环中OLED显示中断中的数据不正确
  • ¥15 这个视频里的stm32f4代码是怎么写的
  • ¥15 JNA调用DLL报堆栈溢出错误(0xC00000FD)
  • ¥15 请教SGeMs软件的使用