dqd3690 2018-06-19 20:48
浏览 48
已采纳

PHP处理带有随机数量项目的清单

I have a HTML Table which is used as a checklist. There are multiple checklists and user can create their own checklist and items as well. This checklist have a random amount of rows.

$table .= "<tr style='cursor: pointer; border: 1px solid black;' onclick='selectVal(this)'>
                          <td style='border: 1px solid transparent; width: 5%;' class='cbTrue'><input type='hidden' value='".$srcarr['id']."' name='item_id' /><input type='checkbox' name='".$srcarr['id']."_True' /></td>
                          <td style='border: 1px solid transparent; width: 30%;'>".$srcarr['item']."</td>
                          <td style='border: 1px solid transparent; width: 30%;'><input type='hidden' class='ckTimeStamp' /></td>
                     </tr>";

$srcarr is my array which comes from a MySQLI query and contains the information of the ID of an Item or the Name oft an Item.

My problem is: I want to save the items with the information if they have been checked and at which time in a MySQL Database. But I have no idea how to know after the form have been posted to PHP how I can separate the information about the single items. Does anybody have an idea?

  • 写回答

3条回答 默认 最新

  • douyimin1083 2018-06-19 21:00
    关注

    As I understood, you have some rows to add and you need to create a unique name for each input.

    Try this:

    <input type='hidden' value='".$srcarr['id']."' name='item_id[".$srcarr['id']."]' /><input type='checkbox' name='".$srcarr['id']."_True' />
    

    Then in the form processing, loop through $_POST['item_id'] and from keys of the array check if is set $_POST[$key . '_TRUE']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测