跟踪数组中的更改,然后将数组提交到同一页面

track change in an array then submit the array to the same page

我有以下php代码(我省略了代码中不相关的部分):

<?php
echo "<form action=$_SERVER[PHP_SELF] method=\"POST\">"; 
echo "<table>"; 
for ($i=0;$i<$num_rows;$i+=1) {  
    echo "<tr>";  
    echo "<td align=center>$variable1[$i]</td>";  
    echo "<td align=center>$variable2[$i]</td>";  
    echo "<td align=center><input type=\"text\" name=\"variable3[$i]\" value=\"$variable3[$i]\" /></td></tr>";  
    echo "<input type=\"hidden\" name=\"variable1[$i]\" value=\"$variable1[$i]\">";  
    echo "<input type=\"hidden\" name=\"variable2[$i]\" value=\"$variable1[$i]\">";  
    echo "<input type=\"hidden\" name=\"variable3[$i]\" value=\"$variable1[$i]\">";  
}  
echo "<tr><td colspan=\"3\"><input name=\"action\" type=\"submit\" value=\"Update\"></td></tr>";  
echo "</table>";  
echo "</form>";  
?>

我想通过 POST 方法将变量传递到同一页面。该代码从数据库中检索数据并将其列在 table 中。但是,我希望能够在执行此操作后手动修改 variable3 并提交数组。问题是在我修改 variable3 之前提交了数组。如何提交修改了 variable3 值的数组?如何检查 variable3 是否被修改并在之后进行提交?谢谢。

像这样删除第 11 行

<?php
echo "<form action=$_SERVER[PHP_SELF] method=\"POST\">"; 
echo "<table>"; 
for ($i=0;$i<$num_rows;$i+=1) {  
    echo "<tr>";  
    echo "<td align=center>$variable1[$i]</td>";  
    echo "<td align=center>$variable2[$i]</td>";  
    echo "<td align=center><input type=\"text\" name=\"variable3[$i]\" value=\"$variable3[$i]\" /></td></tr>";  
    echo "<input type=\"hidden\" name=\"variable1[$i]\" value=\"$variable1[$i]\">";  
    echo "<input type=\"hidden\" name=\"variable2[$i]\" value=\"$variable1[$i]\">";  
}  
echo "<tr><td colspan=\"3\"><input name=\"action\" type=\"submit\" value=\"Update\"></td></tr>";  
echo "</table>";  
echo "</form>";  
?>

现在您可以通过检查 $_POST['variable3'] 的值来查看它是否已更改。