doujianqin5172 2013-10-06 18: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 18: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条)

报告相同问题?

悬赏问题

  • ¥100 使用matlab解决含分段变量的优化问题
  • ¥15 matlab基于鲸鱼算法优化vmd
  • ¥20 PCB设计与制作问答
  • ¥20 课堂跑如何下载ppt
  • ¥15 有没有哥看着画下电路
  • ¥15 STM32阿里云平台显示不了传感器采集的数据
  • ¥20 三菱FX系列PLC上位机串口下指令置位M64和M65,这两条指令分别是什么呢?
  • ¥15 有关结冰模拟程序咨询
  • ¥15 ubuntu服务器配置dns域名后无法访问其他域名
  • ¥50 本人复制了一个关于股票指标的代码,但是运行失败,有没有人帮我解决一下