-
Notifications
You must be signed in to change notification settings - Fork 10
/
cities.php
172 lines (141 loc) · 6.74 KB
/
cities.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "travelscapes";
// Create a connection to the database
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$selectedRegions = [];
$selectedSeasons = [];
$selectedDays = [];
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve filter values from the form
$selectedRegions = isset($_POST["region"]) ? $_POST["region"] : [];
$selectedSeasons = isset($_POST["season"]) ? $_POST["season"] : [];
$selectedDays = isset($_POST["days"]) ? $_POST["days"] : [];
}
// Build the SQL query based on selected filters
$sql = "SELECT * FROM cities WHERE 1";
if (!empty($selectedRegions)) {
if (!in_array("All", $selectedRegions)) {
$sql .= " AND region IN ('" . implode("','", $selectedRegions) . "')";
}
} else {
$selectedRegions = ["All"];
}
if (!empty($selectedSeasons)) {
if (!in_array("All", $selectedSeasons)) {
$sql .= " AND season IN ('" . implode("','", $selectedSeasons) . "')";
}
} else {
$selectedSeasons = ["All"];
}
if (!empty($selectedDays)) {
if (!in_array("All", $selectedDays)) {
$sql .= " AND days IN ('" . implode("','", $selectedDays) . "')";
}
} else {
$selectedDays = ["All"];
}
// Execute the SQL query
$result = $conn->query($sql);
// Create an array to store the data
$data = [];
// Loop through the results and add them to the array
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./css/cities.css">
<script>
function toggleDropdown(filterName) {
var dropdownContent = document.getElementById(filterName + "Dropdown");
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
}
</script>
</head>
<body>
<div class="navbar">
<span class="logo">Travelscapes</span>
</div>
<div class="content-container">
<h1>Travel Packages</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="filter-box">
<div class="custom-dropdown">
<span onclick="toggleDropdown('region')">Region</span>
<div id="regionDropdown" class="custom-dropdown-content">
<label><input type="checkbox" name="region[]" value="All" <?php if (in_array("All", $selectedRegions)) echo "checked"; ?>>All</label>
<label><input type="checkbox" name="region[]" value="North" <?php if (in_array("North", $selectedRegions)) echo "checked"; ?>>North</label>
<label><input type="checkbox" name="region[]" value="South" <?php if (in_array("South", $selectedRegions)) echo "checked"; ?>>South</label>
<label><input type="checkbox" name="region[]" value="East" <?php if (in_array("East", $selectedRegions)) echo "checked"; ?>>East</label>
<label><input type="checkbox" name="region[]" value="West" <?php if (in_array("West", $selectedRegions)) echo "checked"; ?>>West</label>
<label><input type="checkbox" name="region[]" value="Central" <?php if (in_array("Central", $selectedRegions)) echo "checked"; ?>>Central</label>
<label><input type="checkbox" name="region[]" value="North-East" <?php if (in_array("North-East", $selectedRegions)) echo "checked"; ?>>North-East</label>
</div>
</div>
<div class="custom-dropdown">
<span onclick="toggleDropdown('season')">Season</span>
<div id="seasonDropdown" class=" custom-dropdown-content">
<label><input type="checkbox" name="season[]" value="All" <?php if (in_array("All", $selectedSeasons)) echo "checked"; ?>>All</label>
<label><input type="checkbox" name="season[]" value="Winter" <?php if (in_array("Winter", $selectedSeasons)) echo "checked"; ?>>Winter</label>
<label><input type="checkbox" name="season[]" value="Summer" <?php if (in_array("Summer", $selectedSeasons)) echo "checked"; ?>>Summer</label>
<label><input type="checkbox" name="season[]" value="Monsoon" <?php if (in_array("Monsoon", $selectedSeasons)) echo "checked"; ?>>Monsoon</label>
<label><input type="checkbox" name="season[]" value="Spring" <?php if (in_array("Spring", $selectedSeasons)) echo "checked"; ?>>Spring</label>
<label><input type="checkbox" name="season[]" value="Autumn" <?php if (in_array("Autumn", $selectedSeasons)) echo "checked"; ?>>Autumn</label>
</div>
</div>
<div class="custom-dropdown">
<span onclick="toggleDropdown('days')">Days</span>
<div id="daysDropdown" class="custom-dropdown-content">
<label><input type="checkbox" name="days[]" value="All" <?php if (in_array("All", $selectedDays)) echo "checked"; ?>>All</label>
<label><input type="checkbox" name="days[]" value="3" <?php if (in_array("3", $selectedDays)) echo "checked"; ?>>3</label>
<label><input type="checkbox" name="days[]" value="5" <?php if (in_array("5", $selectedDays)) echo "checked"; ?>>5</label>
<label><input type="checkbox" name="days[]" value="7" <?php if (in_array("7", $selectedDays)) echo "checked"; ?>>7</label>
</div>
</div>
</div>
<input type="submit" value="Apply">
</form>
<?php
echo "<table border='1'>";
echo "<tr>";
echo "<th>City ID</th>";
echo "<th>City</th>";
echo "<th>Region</th>";
echo "<th>Season</th>";
echo "<th>Days</th>";
echo "<th>Cost</th>";
echo "<th>Action</th>";
echo "</tr>";
foreach ($data as $row) {
echo "<tr>";
echo "<td>" . $row["cityid"] . "</td>";
echo "<td>" . $row["city"] . "</td>";
echo "<td>" . $row["region"] . "</td>";
echo "<td>" . $row["season"] . "</td>";
echo "<td>" . $row["days"] . "</td>";
echo "<td>Rs " . $row["cost"] . "</td>";
echo "<td><a href='viewjourney.php?city_id=" . $row["cityid"] . "' class='view-button'>View Journey</a></td>";
echo "</tr>";
}
echo "</table>";
$conn->close();
?>
</div>
<footer>
<p>© 2023 Travelscapes. All rights reserved.</p>
</footer>
</body>
</html>