【发布时间】:2019-08-24 13:04:01
【问题描述】:
如何自动选择从数据库中获取的保存值以选择 HTML 标记。
我有一个房间列表,其中包含酒店名称、房间类型、设施、描述。我想编辑那条记录。当我点击编辑按钮时,它会获取 room_id 以相应地编辑行,所有其他值都成功地自动获取到文本框中,除了选择标签中的值。
这是我从数据库中获取值并回显到相应文本框的代码,选择框除外。我想在选择框中自动选择值。
$query = "SELECT * from room where room_id = '$id'";
$result = mysqli_query($connection, $query) or die ( mysqli_error());
while($row=mysqli_fetch_assoc($result))
{
$room_id=$row['room_id'];
$room_type_id=$row['room_type_id'];
$facilities = $row['facilities'];
$long_description=$row['long_description'];
}
?>
<form action="Edit_Room_Script.php" method="post" enctype="multipart/form-data">
<label class="form-label">Hotel Name</label>
<select class="form-control" name="name" id="name">
<?php
$sel_cus = "select hotel_name from hotels ";
$res_cus = mysqli_query($connection, $sel_cus);
while ($row = mysqli_fetch_array($res_cus)) {?>
<option value="<?php echo $row['hotel_id'];?>"><?php echo $row['hotel_name'];?></option><?php}?>
</select>
<label class="form-label">Room Type</label>
<select class="form-control" name="room_type" id="room_type">
<?php
$sel_cus = "select Room_Type_Id,Room_Type_Name from room_type ";
$res_cus = mysqli_query($connection, $sel_cus);
while ($row = mysqli_fetch_array($res_cus)) {?>
<option value="<?php echo $row['Room_Type_Id'];?>">
<?php echo $row['Room_Type_Name'];?></option>
<?php
}
?>
</select>
<label class="form-label">Facilities</label>
<input class="form-control" type="text" id="facilities" value="<?php echo $facilities;?>" name="facilities" autocomplete="Off" required >
<button class="btn btn-success btn-cons" type="submit" name="update" id="update"> Update Room</button>
</form>
我的 html 表中有一行如下所示
高级酒店名称房型设施操作
1 Serena Super ABC 编辑
当我单击编辑按钮时,我需要编辑从数据库中成功自动获取设施值并在文本框中设置但未设置酒店名称和房间类型的位置。在酒店名称和房间类型的选择标签中,它填充了除 serena 和 super 之外的所有酒店名称和房间类型我怎么能做到这一点请用一些代码指导。 谢谢
【问题讨论】: