doucong1992 2015-10-23 10:52
浏览 17
已采纳

单个字段的数组

I'm quite confused on how to access the values of a field, i have 2 fields which accepts several inputs let's call it r_id[ ] and qty[ ] and i need to access each of their values independently

now supposedly this should loop depending on how many r_id's are inside the input post

foreach ($_POST['r_id'] as $row)

r_id is used to verify how many qty s should i put on a r_id

input e.g:

r_id=1,2
qty=3,16

what should happen is on a row with an r_id of 1 i will take the old qty with a sample value of 5 and minus the new qty 3 and then on the second iteration r_id 2 old value of qty minus new qty 16 and so on

these are the forms i used

<input type="text" name="r_id[]" class="form-control inline" value="" required>
<input type="number" step="0.001" name="qty[]" class="form-control inline" value="" required>

i made a javascript to add similar fields up to 10 so that explains why i use an array

  • 写回答

1条回答 默认 最新

  • dp7311 2015-10-23 11:12
    关注

    To process those 2 HTML array fields from the $_POST array you need to do something like this :

    Remember both $_POST['r_id'] and $_POST['qty'] are arrays and they should be delivered to you in the same order they appear on the HTML page. So you can process over one of them in a foreach and then address the other directly

    So as a simple example of looking at what was entered :-

    foreach ($_POST['r_id'] as $idx => $id) {
        echo 'r_id - ' . $id . ' was entered with qty ' . $_POST['qty'][$idx];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分