doujianqin5172 2013-10-06 10:18
浏览 40
已采纳

带有多个字段的HTML PHP表单

I have a html form with 5 rows and 30 fields. Note the attached image. image

I have to capture all of these fields in an array to later convert to a csv file. Each field is labelled at follows: qt1, fa1, en1, et1, ba1, qt2, fa2, etc... Instead of taking each row and adding them to an array in php one at a time is there an easy(ier) way to accomplish this?

I can easily take each row and add them to an array the issue with this i feel would be the speed of the script and the fact that i will have to write 30 lines of array data in the php script.

  • 写回答

2条回答 默认 最新

  • dongqing6755 2013-10-06 10:23
    关注

    Is this what you are looking for?

    <?php
    for($i = 0; $i < 30; $i++): ?>
        <input name="qt[<?php echo $i; ?>]"/>
        <input name="fa[<?php echo $i; ?>]"/>
        <input name="en[<?php echo $i; ?>]"/>
        <input name="et[<?php echo $i; ?>]"/>
        <input name="ba[<?php echo $i; ?>]"/>
    <?php
    endfor;
    ?>
    

    On the server side, you will receive all this data in your $_POST variable anyways, so it will all be in an array regardless. This has an advantage of saving all your values of the same row with the same index and all the same data types under one array.

    Not sure about performance, but code readability and maintenance is alot easier like this.

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部