-
Notifications
You must be signed in to change notification settings - Fork 1
/
viewmenu.php
89 lines (76 loc) · 2.68 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
<?php
include_once 'header.php';
?>
<style>
<?php include 'css/menu.css'; ?>
</style>
<div class="container">
<div class="row">
<div class="col-md-3 ">
<?php
// Display a message when the user logs in
if (isset($_SESSION['u_id'])) {
echo "<h2>".($_SESSION['u_uid']."</h2>");
}
?>
<div class="list-group ">
<a href="user.php" class="list-group-item list-group-item-action ">Profile</a>
<a href="viewmenu.php" class="list-group-item list-group-item-action active">View Menu</a>
<a href="uploadmenu.php" class="list-group-item list-group-item-action">Edit Menu</a>
<a href="chatbot.php" class="list-group-item list-group-item-action">Saved ChatBot</a>
<a href="order.php" class="list-group-item list-group-item-action">Order</a>
<a type="button" href="/editblocks.php" style="width:100%; margin-top:20px" class="btn btn-success btn-lg">Create your bot !</a>
</div>
</div>
<center>
<div class="col-md-09">
<h3>Menu:</h3>
<?php
$server = "db4free.net";
$username = "scratchbot";
$password = "qaz123wsx";
$dbname = "scratchbot";
// Create connection
$conn = new mysqli($server, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT menu FROM menudata WHERE user_id=".$_SESSION['u_id'];
$result = $conn->query($sql);
//echo ($result);
//echo json_decode($result);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//echo $row["menu"] . "<br>";
$result_decode = json_decode($row["menu"], true);
//$test = '[{"name": "Burger", "price": "$6.99"}, {"name": "Egg","price": "$3.99"}]';
//echo $test;
//$test_decode = json_decode($test, true);
//print_r($res); Array
//var_dump($res);
//$character = json_decode($row["menu"]);
//echo $character->name;
if (!empty($result_decode)) {
foreach ($result_decode as $key => $value) {
echo "<h2>" . $value["name"] . "," . $value["price"] . "</h2>" . "<br>";
}
}
}
} else { //No menu for corresponding user
echo "<h2>Oops, looks like don't have a menu...</h2>";
echo "<h2>Click here to type a menu <a href=\"uploadmenu.php\">Click Here<br></a></h2>";
}
$conn->close();
?>
</center>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include_once 'footer.php';
?>