首页 > 解决方案 > 工作票预订系统无法验证数据

问题描述

例如,座位号2 5 7 8 9 25已预订,因此应禁用此功能,并且公共汽车上共有 49 个座位。

我正在从数据库中获取数据,但我无法使用已禁用的预订票验证它。

这是代码:

<?php  include_once("connect.php");
  $query = "SELECT `seat_no` FROM `booked` WHERE `status`='booked'";
  $exexquery = mysqli_query($con, $query); 
?> 

<form action="index.php" method="POST">
  <div class="row" style="width: 20%;margin-left: 20%"> 
  <h2>Select seats</h2>

  <?php
    $x=1;    
    while(($result_row = mysqli_fetch_assoc($exexquery)) || ($x < 50)) { 
      if($result_row['seat_no'] == $x ) {
  ?>

  <div class="col-md-3">
    <p><input type="checkbox" name="requiring[]" value="<?php echo $i;?>" required class="required_group" disabled><?php echo $x;?></p>
  </div>

  <?php
      }
      else {
  ?>

  <div class="col-md-3">
    <p><input type="checkbox" name="requiring[]" value="<?php echo $i;?>" required class="required_group"><?php echo $x;?></p>
  </div>

  <?php
      }
      $x++;
    }
  ?>

  </div>
  <input type="submit" name="submit" value="feel passenger details" style="margin-left:25%"> 
</form>

标签: phphtml

解决方案


首先要获取49您需要删除 where 子句的所有记录

$query = "SELECT `status`,`seat_no` FROM `booked`";// now you will get all 49 rows

status改为检查,同时$x < 50从此处删除条件

  while($result_row = mysqli_fetch_assoc($exexquery)) { 
    if($result_row['status'] == 'booked') {
       // Add html to display booked seats [2, 5, 7, 8, 9, 25]
    }else{
      // Add html to display available seats
    }

推荐阅读