我的php代码与下面类似。如果我选择并提交选项,则所选值将消失。如何在提交后的下拉列表中显示所选值?
<select name = "org">
<?php
$query = "select org from txtable group by org";
$result = mssql_query ($query);
while ($record = mssql_fetch_array ($result))
{
echo "<option value = '".$record[0]."'>". $record[0]. "</option>";
}
?>
</select>
注意:我已经搜索了类似的问题,但没有一个真正帮助过我。
答案 0 :(得分:1)
<select name = "org">
<?php
$query = "select org from txtable group by org";
$result = mssql_query ($query);
while ($record = mssql_fetch_array ($result))
{
if($_POST['org'] == $record[0])
{
echo "<option selected value = '".$record[0]."'>". $record[0]. "</option>";
}
else
{
echo "<option value = '".$record[0]."'>". $record[0]. "</option>";
}
}
?>
</select>
它接受前一个post变量并检查它是否等于在SQL结果中找到的值