简体   繁体   English

动态多维表格

[英]Dynamic multidimensional post form

I have a form with a variable number of inputs. 我有一个具有可变数量输入的表单。 The inputs are inside the table and I need to get three values from them: the row, the column and the actual value inside the input. 输入在表格内部,我需要从中获取三个值:行,列和输入中的实际值。

Some may be populated some may not and I need all their values to update a mysql db (row and column to know what to update, value to know the new value to insert in the database). 有些可能是填充的,有些可能没有,我需要所有值来更新mysql数据库(行和列知道要更新的内容,值以了解要插入数据库的新值)。

This is my form (an example version of it): 这是我的表单(它的一个示例版本):

<form method="post" action="">
      <input name="data[111][222]" value="2" />
      <input name="data[112][221]" value="0" />
      <input name="data[113][223]" value="4" />
      //goes on
      <input name="data[324][435]" value="11" />
      <input name="data[325][436]" value="" />
</form>

And that's as far as I go. 这就是我的目标。 How can I get the data from this form so I can do a simple update in my database that goes like this (for all the affected inputs): 如何从这个表单中获取数据,以便我可以在我的数据库中进行这样的简单更新(对于所有受影响的输入):

   update table set res="value_from_input" where row="row_value" and col="col_value"
<form method="post" action="">
      <input name="data[111][222]" value="2" />
      <input name="data[112][221]" value="0" />
      <input name="data[113][223]" value="4" />
      <input name="data[324][435]" value="11" />
      <input name="data[325][436]" value="" />
      <input type="submit" />
</form>
<?php
foreach ($_POST['data'] as $k1 => $v1)
{
    foreach ($v1 as $k2 => $v2)
    {
        echo "<p>k1:".$k1."; k2: ".$k2."; value: ".$v2."</p>";
        $query = "update table set res='$v2' where row='$k1' and col='$k2'";
        mysql_query($query);
    }
}
?>
foreach($_POST['data'] as $row => $row_array)
{
   foreach($row_array as $col => $value)
   {
      // Sanitize all input data before entry
      $mysql = "UPDATE table SET res='$value' WHERE row='$row' AND col='$col'";
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM