Php 如何在HTML表单中创建此数组结构?
我有以下HTML表单,它是从MySQL数据库中的表动态生成的Php 如何在HTML表单中创建此数组结构?,php,mysql,arrays,multidimensional-array,Php,Mysql,Arrays,Multidimensional Array,我有以下HTML表单,它是从MySQL数据库中的表动态生成的 <form method="post" name="chapters" action="ChaptersUpdate.php"> <input type='text' name='id' value='{$row['id']}'> <input type='text' name='name' value='{$row['name']}'> <input type='password' name
<form method="post" name="chapters" action="ChaptersUpdate.php">
<input type='text' name='id' value='{$row['id']}'>
<input type='text' name='name' value='{$row['name']}'>
<input type='password' name='password' value={$row['password']};>
<input type='submit'>
</form>
我尝试了name='chapter[][id]'/name='chapter[][name]'/name='chapter[][password]'的各种组合,但收效甚微。数组数据结构从来不像我希望的那样
有什么想法吗?您只需像这样创建表单即可
<form method="post" name="chapters">
<?php
for($i = 0; $i <3; $i++)
{
echo "ID: <input type='text' name='chapters[$i][id]' /> <br />";
echo "Name: <input type='text' name='chapters[$i][name]' /> <br />";
echo "Password: <input type='text' name='chapters[$i][password]' /> <br /> ";
echo "<Br />";
}
?>
<input type='submit'>
</form>
以下内容似乎对我有用:
没错,所以我实际上也在做类似的事情。实际创建这些输入字段的PHP组件是:while($row=mysql\u fetch\u array($result)){echo”“;},其中$result=mysql\u query(“从章节中选择*)。奇怪的是,当我检查实际生成的HTML页面的源代码时,它没有显示“chapter[1][id]”……它只显示“chapter[][id]”。这可能是问题的一部分吗?看看我的代码,你会看到($i=0;$i ohhhh)的,那么在我的例子中,for循环会在我开始时的while()循环中吗?
<form method="post" name="chapters">
<?php
for($i = 0; $i <3; $i++)
{
echo "ID: <input type='text' name='chapters[$i][id]' /> <br />";
echo "Name: <input type='text' name='chapters[$i][name]' /> <br />";
echo "Password: <input type='text' name='chapters[$i][password]' /> <br /> ";
echo "<Br />";
}
?>
<input type='submit'>
</form>
if(isset($_POST['chapters']))
{
echo "<pre>";
print_r($_POST['chapters']);
}
Array
(
[0] => Array
(
[id] => 1
[name] => Name1
[password] => Password1
)
[1] => Array
(
[id] => 2
[name] => name 2
[password] => password 2
)
[2] => Array
(
[id] => 2
[name] => name 3
[password] => Password
)
)
<input type='text' name='chapters[0][id]'>
<input type='text' name='chapters[0][name]'>
<input type='password' name='chapters[0][password]'>
<input type='text' name='chapters[1][id]'>
<input type='text' name='chapters[1][name]'>
<input type='password' name='chapters[1][password]'>