我想将用户输入插入到一个php表中。例如,如果我从前一页定义一个2x3表(2行和3列),输入屏幕将显示6个输入,供您填写任何您想要的内容。然后将6个内容变量插入到表中。我相信一个数组和可能是一个foreach循环可能是必要的。但是,我不确定如何让用户输入内容继续到下一页并正确插入到表格中。我也试图把它列入一个列表,但我假设如果表问题可以解决,它应该是相同的列表。任何帮助将不胜感激。PHP动态用户输入到php表
//页,其中定义输入的显示
$row = (isset($_POST['rows']) ? $_POST['rows'] : null);
$col = (isset($_POST['columns']) ? $_POST['columns'] : null);
$list = (isset($_POST['listitems']) ? $_POST['listitems'] : null);
$list2 = (isset($_POST['listitems2']) ? $_POST['listitems2'] : null);
array('[content[]');//Not sure if array should be here or on next page
$y = $list;
$z = $list2;
$x = $row * $col;
for ($i = 1; $i <= $x; $i++) {
echo "$i<input type='text' name='content[]' required> <br>";
}
for ($t = 1; $t <= $y; $t++) {
echo "$t<input type='text' name='content[]' required> <br>";
}
for ($s = 1; $s <= $z; $s++) {
echo "$s<input type='text' name='content[]' required> <br>";
}
echo "<input type='submit' name='submit2' value='Submit'/>
<input type='hidden' name='method' value='post' />
<input type='hidden' name='unorderedinput' value='$list' />
<input type='hidden' name='orderedinput' value='$list2' />
<input type='hidden' name='rowsinput' value='$row' />
<input type='hidden' name='columnsinput' value='$col' />
<input type='hidden' name='cont' value='content[]' />";
echo "</form>";
//页面在显示表中。
$trow = $_POST['rowsinput'];
$tcol = $_POST['columnsinput'];
$ulist = $_POST['unorderedinput'];
$olist = $_POST['orderedinput'];
$tcontent = $_POST['cont'];
echo "<table border='1'>";
for ($tr = 1; $tr <= $trow; $tr++) {
echo "<tr>";
for ($td = 1; $td <= $tcol; $td++) {
echo "<td align='center'>". "$tcontent". "</td>";//I'm not sure if this is correct
}
echo "</tr>";
}
echo "</table>";
它工作完美。谢谢。 – mastodon
不客气! – trincot