-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewmenu.php
94 lines (74 loc) · 2.25 KB
/
viewmenu.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
<?php
session_start();
echo"<link rel= stylesheet href =demo.css>";
if (isset($_SESSION["name"])) {
$hotelName = $_SESSION["name"];
} else {
echo "Hotel name not found in the session.";
exit;
}
$servername = "localhost";
$username = "Atharav";
$password = "Atharav@31";
$dbname = "project";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Step 1: Retrieve the hotel ID based on the hotel name
$sql = "SELECT id FROM hotel WHERE name = ?";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
die("Prepare failed: " . $conn->error);
}
$stmt->bind_param("s", $hotelName); // Assuming `name` is a string
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$hotelId = $row["id"];
}
} else {
echo "Hotel not found for name: $hotelName";
exit; // Exit if the hotel is not found
}
$stmt->close();
// Step 2: Get Menu Items with Price (Make sure the column names match your database)
$sql = "SELECT dish_name,dish_type, price FROM menus WHERE id = ?";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
die("Prepare failed: " . $conn->error);
}
$stmt->bind_param("i", $hotelId); // Assuming `hotel_id` is an integer
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "<h2>Menu for Hotel: $hotelName</h2>";
$srno=1;
echo "<table border='1'>
<thead>
<tr>
<th> Srno</th>
<th>Dish Name</th>
<th>Type</th>
<th>Price</th>
</tr>
</thead>
<tbody>";
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo"<td>".$srno."</td>";
echo "<td>" . $row["dish_name"] . "</td>";
echo "<td>". $row["dish_type"] ."</td>";
echo "<td>Rs. " . number_format($row["price"], 2) . "</td>";
echo "</tr>";
$srno++;
}
echo "</tbody></table>";
echo "<a href=customerbookinghtml.php><button type=button class=back-button>BACK</button></a>";
} else {
echo "No menu items found for Hotel: $hotelName";
}
$stmt->close();
$conn->close();
?>