我正在开发一个注册系统,如果该房间的注册会员人数少于5,则可以查询数据库中的可用房间列表。我想要一个下拉列表,按下按钮点击可用房间列表,而不刷新页面。
这是html:
<div class="too-many">
<div class="center-too-many">
<div class="label-room">
<div class="labas"><label for="hostel">Hostel: </label></div>
<div class="labas"><label for="r_type">Room Type: </label></div>
</div>
<div class="labels-input room">
<!--Hostel-->
<?php
if ($row['gender'] == 'Male') {
$option1 = 'Banabas';
$option2 = 'Banabas Annex';
}
else {
$option1 = 'Faith';
$option2 = 'Faith Annex';
}?>
<div class="labas"><div class="form-group">
<div class="input-group input-group-sm">
<select class="form-control" name="hostel" required>
<option></option>
<option><?php echo $option1; ?></option>
<option><?php echo $option2; ?></option>
</select>
</div>
</div></div>
<!--Hostel-->
<!--Room Type-->
<div class="labas"><div class="form-group">
<div class="input-group input-group-sm">
<select class="form-control" name="r_type" required>
<option></option>
<option>Executive</option>
<option>Standard</option>
</select>
</div>
</div></div>
<!--Room Type-->
</div>
<input type="submit" name="check" value="CHECK AVALIBILITY" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="magic" />
<div class="label-room">
<div class="labas"><label for="av_rooms">Avalible rooms: </label></div>
</div>
<div class="labels-input room">
<!--Room Class-->
<div class="labas"><div class="form-group">
<div class="input-group input-group-sm">
<select class="form-control" name="av_rooms">
<?php echo $msg; ?>
</select>
</div>
</div></div>
<!--Room Class-->
</div>
<input type="submit" name="register" value="REGISTER" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="magic" />
</div>
</div>
</form>
和php:
<?php
if (isset($_POST['check'])) {
$hostel = $_POST['hostel'];
$type = $_POST['r_type'];
if ($type == 'Standard') {
$_POST['r_type'] = 'SR';
}
else {
$_POST['r_type'] = 'ER';
}
if ($hostel == 'Banabas' && $type == 'SR') {
$query = 'SELECT room_no, COUNT(room_no) as count FROM banabas_sr GROUP BY room_no HAVING count BETWEEN 0 AND 6';
$ex = mysql_query($query);
while ($row = mysql_fetch_array($ex)) {
echo $msg = "<option value='" . $row['room_no'] . "'>" . $row['room_no'] . "</option>";
}
}
}
?>
当我点击check
时,它应该填充下拉列表,register
会将数据写入数据库。下拉列表不会填充。我不知道它是不是sql查询,我使用的语法或页面仍然刷新的事实,我不知道如何让它停止。一点点见解会非常有帮助。