Repository navigation
Expand file tree
/
Copy pathsearch.php
More file actions
70 lines (64 loc) · 2.23 KB
/
Copy pathsearch.php
File metadata and controls
70 lines (64 loc) · 2.23 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
64
65
66
67
68
69
70
<?php
include 'includes/db.php';
include 'includes/header.php';
$flights = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$origin = $_POST['origin'];
$destination = $_POST['destination'];
$sql = "SELECT * FROM flights WHERE origin LIKE '%$origin%' AND destination LIKE '%$destination%' ";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
$flights[] = $row;
}
}
?>
<div class="container mt-5">
<link rel="stylesheet" type="text/css" href="Assets/C.css">
<h2>Cari Tiket</h2>
<form method="POST">
<div class="form-row">
<div class="form-group col-md-4">
<label>Asal</label>
<input type="text" name="origin" class="form-control">
</div>
<div class="form-group col-md-4">
<label>Tujuan</label>
<input type="text" name="destination" class="form-control">
</div>
</div>
<button type="submit" class="btn btn-primary">Cari</button>
</form>
<?php if (!empty($flights)): ?>
<table class="table table-bordered mt-4">
<thead>
<tr>
<th>Asal</th>
<th>Tujuan</th>
<th>Tanggal Keberangkatan</th>
<th>Harga</th>
<th>Kursi Tersedia</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php foreach ($flights as $flight): ?>
<tr>
<td><?= $flight['origin']; ?></td>
<td><?= $flight['destination']; ?></td>
<td><?= $flight['departure_date']; ?></td>
<td>Rp <?= number_format($flight['price'], 2, ',', '.'); ?></td>
<td><?= $flight['seats']; ?></td>
<td>
<?php if ($flight['seats'] > 0): ?>
<a href="booking.php?flight_id=<?= $flight['id']; ?>" class="btn btn-primary btn-sm">Pesan</a>
<?php else: ?>
<span class="text-danger">Penuh</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<?php include 'includes/\footer.php'; ?>