dousuie2222 2012-06-06 13:09
浏览 50
已采纳

Php使用html表中的数据

Ok, so basically I have data I have added to an html table and a save button. I want this button to submit the data in the table to a php function so that I can modify my mysql database using the data. I have the tools to modify the database, as long as I can get the data. However, I have no clue how to do this. What is the best way to accomplish this?

  • 写回答

3条回答 默认 最新

  • duanchuang1935 2012-06-06 13:38
    关注

    In Addition to what @John Conde said, for every record presented in the table, you should create it's respective hidden field i.e. a <input type="hidden"... />
    Considering that tables have rows and columns, I will make some assumptions:

    1. I will assume that the rows are equivalent to the data you have on a per record basis
    2. That the columns are the fields you will update with data on a per record basis

    Going on this assumption (let me assume 3 fields i.e. 3 columns and 2 records)

            Field 1    Field 2    Field 3
    Row 1     a          b          c
    Row 2     d          e          f
    

    For each of these we'll create corresponding input fields in the form we'll create to contain the submit button like so:

    <form action="" method="post">
        <!--Row 1-->
        <input type="hidden" name="field_1[]" value="a" />
        <input type="hidden" name="field_2[]" value="b" />
        <input type="hidden" name="field_3[]" value="c" />
        <!--Row 2-->
        <input type="hidden" name="field_1[]" value="d" />
        <input type="hidden" name="field_2[]" value="e" />
        <input type="hidden" name="field_3[]" value="f" />
        <!-- more rows if they exist -->
        <input type="submit" name="my_btn" value="POST IT!" />
    </form>    
    

    On the PHP side, you could then process the form fields, like so:

    foreach($_POST["field_1"] as $id=>$field1_value){
        $field2_value = $_POST["field_2"][$id];
        $field3_value = $_POST["field_3"][$id];
        .......
    }
    

    Hope this helps

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

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序