我有一个表单选择框,它正确地填充了mysql表中的值,但当它发布时,发布的值是表'manutags‘中的最后一项,而不是框中显示的选定项。有人能告诉我我的逻辑出了什么问题吗?
<p class="formlabel cf text nobox">Tag Style <!--popuplate with tag styles-->
<?$i=1;
while($i<11){?>
<select class="man_sty <?$m='man'.$i++;echo $m?>" name="style_id">
<?
$sql = "SELECT DISTINCT man,style_id FROM manutags WHERE man_id = '$m'";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)){
?>
<option value="<?=$row[1];?>"><?echo $row[1]?></option><!-- tag dropdown values-->
<?}?>
</select>
<?}?>
HTML
<p class="formlabel cf text nobox">
Tag Style
<select class="man_sty man1" name="style_id_1" style="display: none;">
<option selected="" value="Kliktag">Kliktag</option>
<option value="RD2000">RD2000</option>
<option value="Button-R">Button-R</option>
<option value="SnappTagg">SnappTagg</option>
<option value="AutoEID">AutoEID</option>
</select>
<select class="man_sty man2" name="style_id_2" style="display: none;">
<option selected="" value="rototag">rototag</option>
</select>
<select class="man_sty man3" name="style_id_3" style="display: inline;">
<option selected="" value="Qwik">Qwik</option>
<option value="Zee">Zee</option>
</select>
</p>发布于 2013-02-02 16:31:51
您的所有菜单都有相同的name="style_id"。因此,当您提交表单时,它们都设置了$_POST['style_id']。因为只有一个同名的变量,所以你只能得到最后一个变量。你需要给它们不同的名字,这样你才能从每一个中选择。
尝试:
<select class="man_sty <?$m='man'.$i++;echo $m?>" name="style_id[]">那么$_POST['style_id']将是一个包含每个选择的值的数组。
发布于 2013-02-02 16:32:08
看看这个。似乎您忘记更改每个select的name。
<?php
for ($i = 1; $i <= 10; $i++) {
$manId = "man" . $i;
echo "<select class=\"man_sty {$manId}\" name=\"style_id_{$i}\">";
$sql = "SELECT DISTINCT man, style_id FROM manutags WHERE man_id = '{$manId}'";
$result = mysql_query($sql) or die(mysql_error());
$selected = 'selected';
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"{$row[1]}\" {$selected}>{$row[1]}</option>";
$selected = '';
}
echo "</select>";
}
?>发布于 2013-02-02 16:36:06
将您的下拉名称设置为动态。对于10,下拉10个不同的名称。然后选取动态下拉的值。think会给你想要的结果。
https://stackoverflow.com/questions/14659964
复制相似问题