工作票预订系统无法验证数据

时间:2018-06-25 06:49:10

标签: php html

例如,预订了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>

2 个答案:

答案 0 :(得分:1)

首先要获取所有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
    }

答案 1 :(得分:0)

在@ C2486回答中,您还可以将代码缩短为:

<?php
while ($result_row = mysqli_fetch_assoc($exexquery)):
    $disabled = ($result_row['status'] === 'booked') ? ' disabled' : '';
?>
<div class="col-md-3">
    <p><input type="checkbox" name="requiring[]" value="<?php echo $i;?>" required class="required_group"<?php echo $disabled; ?>><?php echo $x;?></p>
</div>
<?php
endwhile;
?>