我在表单中使用下拉列表。如果该值已存在于数据库中,则我希望该值不显示在下拉列表中。
<select name="bank_name" id="bank_name" required>
<option value="">Select Bank</option>
<?php
$query_val = mysql_query("SELECT * from bank order by bankname ");
while($row_subject = mysql_fetch_array($query_val)) {
?>
<option value="<?php echo $row1["bank_name"];?>" <?php if(!empty($_POST['bank_name']) && $_POST['bank_name']==$row_subject['bankname']){echo 'selected="selected"';}?>>
<?php echo $row_subject['bankname'];?>
</option>
<?php } ?>
</select>
如何将数据库中的存储值显示到下拉列表中?
答案 0 :(得分:-1)
请在下面尝试。在选择框选项值中,您定义了错误的值($ row1 [“ bank_name”]),并且查询也未定义orderby
<select name="bank_name" id="bank_name" required>
<option value="">Select Bank</option>
<?php
$query_val = mysql_query("SELECT * from bank order by bankname asc ");
while($row_subject = mysql_fetch_array($query_val)) {
?>
<option value="<?php echo $row_subject["bank_name"];?>" <?php if(!empty($_POST["bank_name"]) && $_POST["bank_name"]==$row_subject["bankname"]){echo 'selected="selected"';}?>>
<?php echo $row_subject["bankname"];?>
</option>
<?php } ?>
</select>