如何提交具有分组/id的表/表单以便稍后检索


How to submit table/form with grouping/id to retrieve later

我正在尝试编写html5和PHP的表单,用户可以填写。当他们点击提交,我希望有一个整体的评估类别,每5列分组,我也可以检索。例如:

<parameters>
  <parameterID>9214</parameterID>
  <parameter>MC Bands</parameter>
  <Yevaluation/>
  <Mevaluation/>
  <Cevaluation/>
  <Kevaluation/>
  <comments/>
</parameters>
<parameters>
  <parameterID>9245</parameterID>
  <parameter>MC Streaks</parameter>
  <Yevaluation/>
  <Mevaluation/>
  <Cevaluation/>
  <Kevaluation/>
  <comments/>
</parameters>

我在把它输入表单和输入表时遇到了麻烦,所以我可以在以后检索它的类别ID。我本来打算用一个隐藏单元格,但它把值固定在了第一个表格单元格里。

这是在table.php:

<form  method="get" action="visEupload.php">
<table id="bigTable" border="1">
    <thead>
     <tr>
     <th id="bandY" class="col3">Bands @263mm Y</th>
     <th id="bandM" class="col3">Bands @263mm M</th>
     <th id="bandC" class="col3">Bands @263mm C</th>
     <th id="bandK" class="col3">Bands @263mm K</th>
     <th id="Comments" class="col3">Comments</th>
     </tr>
    </thead>
    <tbody>
        <tr>
            <td><input name="MCBands" value="9214" id="MCBands" visibility=hidden> <!--this isn't showing up as hidden-->
            <td><input name="Yevaluation" ></td>  //Row 0 Column 1
            <td><input name="Mevaluation" ></td>  //Row 0 Column 2
            <td><input name="Cevaluation" ></td>  //Row 0 Column 3
            <td><input name="Kevaluation" ></td>  //Row 0 Column 4
            <td><input name="comment" ></td>  //Row 0 Column 4
            <!--the above rows will repeat with different id's/names/values/cells, ex. streaks and will be really wide-->
        </tr>
    </tbody>
</table>
  <input id="submit" type="submit" class="list" name="submit" value="Submit To Database" >  
</form>

我有麻烦找到一个很好的例子与表数据提交的形式。我看到了这个,但它是不同的html表格。

点击提交后,我像这样在viseupload。php中检索它,但也许有更好的方法考虑到我每隔几行添加额外的parameterID:

if (isset($_GET['submit'])){
        $Yevaluation= $_GET['Yevaluation'];
        $Mevaluation= $_GET['Mevaluation'];
        $Cevaluation= $_GET['Cevaluation'];
        $Kevaluation= $_GET['Kevaluation'];
        $MCBands= $_GET['MCBands'];
        $comment=$_GET['comment'];
        echo "here:".$Yevaluation.$Mevaluation.$Cevaluation.$Kevaluation.$MCBands.$comment;
        echo "here1";
        echo ("visE upload requested");
    } //submit is set

您可以在输入元素中使用类似数组的名称,例如:

<table id="bigTable" border="1">
    <thead>
     <tr>
     <th id="bandY" class="col3">Bands @263mm Y</th>
     <th id="bandM" class="col3">Bands @263mm M</th>
     <th id="bandC" class="col3">Bands @263mm C</th>
     <th id="bandK" class="col3">Bands @263mm K</th>
     <th id="Comments" class="col3">Comments</th>
     </tr>
    </thead>
    <tbody>
        <tr>
            <td><input name="MCBands[]" value="9214" id="MCBands" type="hidden"> 
            <td><input name="Yevaluation[]" value=""></td>  //Row 0 Column 1
            <td><input name="Mevaluation[]" value=""></td>  //Row 0 Column 2
            <td><input name="Cevaluation[]" value=""></td>  //Row 0 Column 3
            <td><input name="Kevaluation[]" value=""></td>  //Row 0 Column 4
            <td><input name="comment[]" value=""></td>  //Row 0 Column 4
        </tr>
        <tr>
            <td><input name="MCBands[]" value="9215" id="MCBands" type="hidden">
            <td><input name="Yevaluation[]" value=""></td>  //Row 0 Column 1
            <td><input name="Mevaluation[]" value=""></td>  //Row 0 Column 2
            <td><input name="Cevaluation[]" value=""></td>  //Row 0 Column 3
            <td><input name="Kevaluation[]" value=""></td>  //Row 0 Column 4
            <td><input name="comment[]" value=""></td>  //Row 0 Column 4
        </tr>
        <tr>
            <td><input name="MCBands[]" value="9214" id="MCBands" type="hidden">
            <td><input name="Yevaluation[]" value=""></td>  //Row 0 Column 1
            <td><input name="Mevaluation[]" value=""></td>  //Row 0 Column 2
            <td><input name="Cevaluation[]" value=""></td>  //Row 0 Column 3
            <td><input name="Kevaluation[]" value=""></td>  //Row 0 Column 4
            <td><input name="comment[]" value=""></td>  //Row 0 Column 4
        </tr>
    </tbody>
</table>

在后台,你可以使用:

if (isset($_GET['submit'])){
    $arr = array();   
    foreach($_POST["MCBands"] as $key => $val) {
        $arr[] = array(
            "MCBands" => $_POST["MCBands"][$key],
            "Yevaluation" => $_POST["Yevaluation"][$key],
            "Mevaluation" => $_POST["Mevaluation"][$key],
            "Cevaluation" => $_POST["Cevaluation"][$key],
            "Kevaluation" => $_POST["Kevaluation"][$key],
            "comment" => $_POST["comment"][$key]
        );    //semicolon added here ~M
    }
}