过去几天这让我发疯了。我已经用复选框做了类似的事情,并认为这可行,但事实并非如此。我的选择框设置如下..
while ($row = mysql_fetch_array($queryResult2))
{
echo "<table border=\"1\" \"black\" \"solid\">";
echo "<tr><th>News item</th><td>";
echo $row['heading'];
echo "</td></tr>";
echo "<tr><th>Order</th><td>";
if( $row['id'] == 0)
$id = "first";
if( $row['id'] == 1)
$id = "second";
if( $row['id'] == 2)
$id = "third";
if( $row['id'] == 3)
$id = "fourth";
if( $row['id'] == 4)
$id = "fith";
if( $row['id'] == 5)
$id = "sixth";
if( $row['id'] == 6)
$id = "seventh";
if( $row['id'] == 7)
$id = "eighth";
if( $row['id'] == 8)
$id = "ninth";
if( $row['id'] == 9)
$id = "tenth";
echo "<select name='order[]'>
<option value='$id'>". $id ."</option>
<option name='first' value='1'>first</option>
<option name='second' value='2'>second</option>
<option name='order[]' value='3'>third</option>
<option name='order[]' value='4'>fourth</option>
<option name='order[]' value='5'>fith</option>
<option name='order[]' value='6'>sixth</option>
<option name='order[]' value='7'>seventh</option>
<option name='order[]' value='8'>eighth</option>
<option name='order[]' value='9'>ninth</option>
<option name='order[]' value='10'>tenth</option>
</select>";
然后当我执行print_r($ _ POST);
时它会转到下一页Array([order] =&gt; Array([0] =&gt; first [1] =&gt; second [2] =&gt; third [3] =&gt; fourth [4] =&gt; fith [5 ] =&gt;第六[6] =&gt;第七[7] =&gt;第八[8] =&gt;第九[9] =&gt;第十))
如何获取所有数据并将其放入变量中,以便我可以使用此信息更新数据库?
答案 0 :(得分:1)
我相信你会想要类似以下内容:
<form action="some_file.php" method="post">
<select multiple="multiple" name="test[]">
<option value="1">Test 1</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
<option value="4">Test 4</option>
<option value="5">Test 5</option>
</select>
<input type="submit" />
</form>
您在name
项目上不需要option
属性。这可能会让你感到困惑。
我认为你应该做的事情:
multiple="multiple"
添加到select
代码name
输入select
个属性