-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.php
112 lines (107 loc) · 4.14 KB
/
home.php
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
session_start();
$pageTitle = 'Show Flights';
include 'init.php';
include $template . 'header.php';
include $template.'navbar.php';
if(!isset($_SESSION['user'])){
header('Location: login.php');
}
$email = $_SESSION['user']['email'];
$user_id = $_SESSION['user']['user_id'];
$sql = "SELECT * FROM flight";
$stmt = $conn->prepare($sql);
$stmt->execute();
$flights = $stmt->fetchAll();
/*
* SELECT USING JOIN
* */
$sql = "
SELECT * FROM flight
JOIN reservation ON flight.flight_id = reservation.flight_id
WHERE reservation.user_id = $user_id
GROUP BY reservation.flight_id
ORDER BY reservation.flight_id
";
$stmt = $conn->prepare($sql);
$stmt->execute();
$myflights = $stmt->fetchAll();
?>
<div class="container my-5">
<h1>Show Flights</h1>
<table class="table table-dark table-striped">
<thead>
<tr>
<th scope="col">Flight ID</th>
<th scope="col">Departure Location</th>
<th scope="col">Arrival Location</th>
<th scope="col">Departure Time</th>
<th scope="col">Arrival Time</th>
<th scope="col">Price</th>
<th scope="col">Airline</th>
<th scope="col" class="text-center">Controls</th>
</tr>
</thead>
<tbody>
<?php foreach($flights as $flight){ ?>
<tr>
<th scope="row"><?=$flight['flight_id']?></th>
<td><?=$flight['dep_location']?></td>
<td><?=$flight['arrival_location']?></td>
<td><?=$flight['dep_time']?></td>
<td><?=$flight['arrival_time']?></td>
<td><?=$flight['price']?></td>
<td><?=$flight['airline']?></td>
<td class="text-center">
<!-- <form action="book-flight.php?flight_id=--><?php //echo $flight['flight_id']; ?><!--" method="GET">-->
<form action="book-flight.php" method="GET">
<input type="hidden" name="flight_id" value="<?=$flight['flight_id']?>">
<input type="submit" value="Book" class="btn btn-success"/>
</form>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="container my-5">
<h1>My Flights</h1>
<table class="table table-dark table-striped">
<thead>
<tr>
<th scope="col">Flight ID</th>
<th scope="col">Departure Location</th>
<th scope="col">Arrival Location</th>
<th scope="col">Departure Time</th>
<th scope="col">Arrival Time</th>
<th scope="col">Price</th>
<th scope="col">Airline</th>
<th scope="col" class="text-center">Controls</th>
</tr>
</thead>
<tbody>
<?= count($myflights)?:'<tr><td colspan="8" class="text-center">No Flights</td></tr>' ?>
<?php foreach($myflights as $flight){ ?>
<tr>
<th scope="row"><?=$flight['flight_id']?></th>
<td><?=$flight['dep_location']?></td>
<td><?=$flight['arrival_location']?></td>
<td><?=$flight['dep_time']?></td>
<td><?=$flight['arrival_time']?></td>
<td><?=$flight['price']?></td>
<td><?=$flight['airline']?></td>
<td class="text-center">
<!-- <form action="book-flight.php?flight_id=--><?php //echo $flight['flight_id']; ?><!--" method="GET">-->
<form action="delete-seat.php" method="GET">
<input type="hidden" name="flight_id" value="<?=$flight['flight_id']?>">
<input type="submit" value="Cancel" class="btn btn-danger"/>
</form>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php
include $template . 'footer.php';
?>