-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
128 lines (114 loc) · 3.69 KB
/
search.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
ob_start();
include('header.php');
$searchError = "";
$searchResults = array();
if (isset($_GET['location'], $_GET['checkIn'], $_GET['checkOut'])) {
$location = $_GET['location'];
$checkIn = $_GET['checkIn'];
$checkOut = $_GET['checkOut'];
$query = "SELECT * FROM hotel WHERE location LIKE '%$location%' AND availability_status = 'available'";
$result = $con->query($query);
if (!$result) {
$searchError = "Error fetching results: " . $con->error;
} else {
while ($row = $result->fetch_assoc()) {
$homeId = $row['hotel_id'];
$availabilityQuery = "SELECT COUNT(*) as count FROM reservations WHERE hotel_id = $homeId AND check_in_date <= '$checkOut' AND check_out_date >= '$checkIn'";
$availabilityResult = $con->query($availabilityQuery);
if ($availabilityResult) {
$availabilityRow = $availabilityResult->fetch_assoc();
if ($availabilityRow['count'] == 0) {
$searchResults[] = $row;
}
$availabilityResult->free();
} else {
$searchError = "Error checking availability: " . $con->error;
break;
}
}
$result->free();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
.container {
max-width: 1200px;
margin: auto;
padding: 20px;
}
.holiday-home {
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
margin-bottom: 20px;
display: flex;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.home-image {
width: 30%;
object-fit: cover;
}
.holiday-details {
padding: 20px;
width: 70%;
}
.holiday-details h2 {
margin-top: 0;
font-size: 24px;
}
.label {
font-weight: bold;
margin: 10px 0 5px;
}
.buttons {
margin-top: 20px;
}
.btn {
background-color: #28a745;
color: #fff;
padding: 10px 15px;
text-decoration: none;
border-radius: 5px;
}
.btn:hover {
background-color: #218838;
}
</style>
</head>
<body>
<div class="container">
<?php
if (!empty($searchError)) {
echo "<p class='error'>$searchError</p>";
} elseif (!empty($searchResults)) {
foreach ($searchResults as $row) {
echo "<div class='holiday-home'>";
echo "<img src='{$row['image_path']}' alt='{$row['name']}' class='home-image'>";
echo "<div class='holiday-details'>";
echo "<h2>{$row['name']}</h2>";
echo "<p class='label'>Location:</p>";
echo "<p>{$row['location']}</p>";
echo "<p class='label'>Rating:</p>";
echo "<p>{$row['rating']}</p>";
echo "<div class='buttons'>";
echo "<a href='reserve.php?hotel_id={$row['hotel_id']}&checkIn=$checkIn&checkOut=$checkOut' class='btn'>Book Now</a>";
echo "</div>";
echo "</div>";
echo "</div>";
}
} else {
echo "<p>No results found.</p>";
}
?>
</div>
<?php
include("footer.php"); ?>
</body>
</html>