dq13733519262 2015-04-29 15:27 采纳率: 0%
浏览 51

PHP JQuery - 多个字段发布

I am looking for any advice on how to do this, the concept is confusing me. I am not looking for an exact solution, just help with the logic.

I have a HTML form that is like this:

| Name | Price | Comment

Which I then pass to PHP script that updates this as a record inside the database. The problem being is that, I am going going to be creating multiple entries (through JQuery) and I don't know how to pass these as one through to the PHP file. I know that I can do this:

<input type="name" id="name[]" value="" />

And handle each of the posts as an array, and, I can do this for all of the fields inside the form. But is there an efficient way to link them all up?

For example:

If I have 5 new rows then the array is going to be:

$_POST['names'] = {"name1", "name2", "name3", ...}
$_POST['cost'] = {"cost1", "cost2", "cost3", ...}
$_POST['comments'] = {"comment1", "comment2", "comment3", ...}

I hope that this makes sense and someone can help me!

  • 写回答

1条回答 默认 最新

  • dongnu4254 2015-04-29 15:38
    关注

    This can actually be done with HTML alone, and all your values will be structured even better than you suggest.

    <form>
        <div class="row">
            <input name="rows[0][name]"/>
            <input name="rows[0][price]"/>
            <input name="rows[0][comment]"/>
        </div>
        <div class="row">
            <input name="rows[1][name]"/>
            <input name="rows[1][price]"/>
            <input name="rows[1][comment]"/>
        </div>
    </form>
    

    Then in PHP access $_REQUEST['rows'] and see its contents.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题