我有一个由PHP生成的工作选择。
代码:
echo "<form method='post'><select name='selectid'>";
$result_select = mysql_query("SELECT * FROM DB.Table");
while($row_select = mysql_fetch_array($result_select))
{
echo "<option ";
if ($row['Value'] == $row_select['Value'] ) echo 'selected';
echo ">{$row_select['Value']} {$row_select['Value']}
</option>";
}
echo "</select></form>";
现在的问题是,我想从select中选择$ _POST所选的值。它也在起作用。但是我希望得到没有&amp; nbsp
的字符串我试过了:
$text_description=" Helloworld! ";
$text_description = str_replace(' ', '', $text_description);
echo $text_description;
它正在发挥作用。但是当我更换
$text_description=" Helloworld! ";
到
$text_description=$_POST['selectid'];
它不再起作用了。
答案 0 :(得分:2)
您只需为选项添加值属性:
echo "<form method='post'><select name='selectid'>";
$result_select = mysql_query("SELECT * FROM DB.Table");
while($row_select = mysql_fetch_array($result_select))
{
echo "<option value='{$row_select['Value']}'";
if ($row['Value'] == $row_select['Value'] ) echo 'selected';
echo ">{$row_select['Value']} {$row_select['Value']}
</option>";
}
echo "</select></form>";