-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathseat_layout.php
More file actions
63 lines (44 loc) · 1.42 KB
/
Copy pathseat_layout.php
File metadata and controls
63 lines (44 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
// if passenger session is not then will regirect to login.
session_start();
if(!isset($_SESSION['passenger_id'])){
header("Location: login.html");
exit();
}
$conn = mysqli_connect('localhost','root','','btrs');
if (!$conn){
die("connection failed");
}
$passenger = $_SESSION['passenger_id'];
$schedule_id = $_GET['schedule_id'];
$sql = "SELECT seat_number FROM ticket
WHERE schedule_id = $schedule_id AND status = 'book'";
$result = mysqli_query($conn, $sql);
$booked = [];
while($row = mysqli_fetch_assoc($result)){
$booked[] = $row['seat_number'];
}
?>
<h2> select seat </h2>
<?php
$busSeatsSql = "SELECT bus.total_seats FROM schedule
JOIN bus ON schedule.bus_id = bus.bus_id
WHERE schedule.schedule_id = $schedule_id";
$seatResult = mysqli_query($conn, $busSeatsSql);
$seatRow = mysqli_fetch_assoc($seatResult);
$total_seats = $seatRow['total_seats'];
for($seat = 1; $seat <= $total_seats; $seat++){
if(in_array($seat, $booked)){ // in_array(value, array) //in_array(5, [2,5,7,12])
echo "<button disabled style='background:red;color:white;margin:5px'>
Seat $seat (Booked)
</button>";
}else{
echo "<a href='book.php?Schedule_id=$schedule_id&Seat_number=$seat'>
<button style='background:green;color:white;margin:5px'>
Seat $seat (Free)
</button>
</a>";
}
if($seat % 4 == 0) echo "<br>"; // new row like bus seats
}
?>