【问题标题】:Is it possible to recuperate data entered by user in a dynamic table [closed]是否可以恢复用户在动态表中输入的数据[关闭]
【发布时间】:2017-06-07 03:42:22
【问题描述】:

我使用 html+php 创建了一个动态表,输入类似于表单(这实际上是一个矩阵)和 我想知道是否可以恢复用户在动态表中输入的数据?这是我的代码:

<?php 
$rows = 3; // define number of rows
echo ' <form action="f.php" method="post">';
echo "<table border='1'>";
for($tr=1;$tr<=$rows;$tr++){
    echo "<tr>";
    echo "<th> E".$tr." </th>";
        for($td=1;$td<=$rows;$td++){
               echo '<td><input type="number" name="etat" placeholder="nb d etat" /></td>';
        }
    echo "</tr>";
}
echo "</table>";
echo '<input type="submit" value="Create Table">';
echo '</form>'
?>

【问题讨论】:

    标签: php html html-table


    【解决方案1】:

    是的,这是可能的,但您必须通过提供行号和列号来创建表单,因为您想创建矩阵:

    $rows = 3; // define number of rows
    echo ' <form action="f.php" method="post">';
    echo "<table border='1'>";
    for($tr=1;$tr<=$rows;$tr++){
        echo "<tr>";
        echo "<th> E".$tr." </th>";
            for($td=1;$td<=$rows;$td++){
                   echo '<td><input type="number" name="etat_'.$tr.'_'.$td.'" placeholder="nb d etat" /></td>';
            }
        echo "</tr>";
    }
    echo "</table>";
    echo '<input type="submit" name="submit" value="Create Table">';
    echo '</form>';
    

    f.php 中获取数据:

    if(isset($_POST['submit'])) {
        print_r($_POST);
    }
    

    它给你输出:

    Array
    (
        [etat_1_1] => 1 //means 1st row 1st column
        [etat_1_2] => 2 //means 1st row 2nd column
        [etat_1_3] => 3 //means 1st row 3rd column
        [etat_2_1] => 4 //means 2nd row 1st column and so on...
        [etat_2_2] => 5
        [etat_2_3] => 6
        [etat_3_1] => 7
        [etat_3_2] => 8
        [etat_3_3] => 9
        [submit] => Create Table
    )
    

    【讨论】:

    • 谢谢它很有帮助:)
    • 很高兴为您提供帮助。请不要忘记投票...@hinata
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 2013-03-09
    • 2011-01-03
    • 1970-01-01
    相关资源
    最近更新 更多