我目前正在设计一个网站,它用PHP从MySQL数据库中读取信息,并打印出每一行的表单。这是使用while循环完成的,因此表单会在循环中回显。但是,每当我提交表单时,很多值都不会被发布,因为页面上有相同的名称和ID的表单。
如何在数据库中打印出每一项的表单并相应地处理此表单?谢谢!
while (*this goes through each row in the database) {
echo "<form name='myForm' id='myForm' method='post' action=''>
<input type='text' name='text1'>
</form>";
}
我想使用一个循环打印一个动态数量的表单。
发布于 2013-09-25 00:18:56
只需在每次迭代中添加一个计数器,就可以更改表单名称和id。
$i = 0;
while (*this goes through each row in the database) {
echo "<form name='myForm" . $i . "' id='myForm" . $i . "' method='post' action=''>
<input type='text' name='text1'>
</form>";
$i++;
}
甚至可能更好的是,如果您对每个记录都有某种类型的唯一数据库id,则使用该id值而不是计数器。
https://stackoverflow.com/questions/18994191
复制相似问题