-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistRatings.php
executable file
·82 lines (75 loc) · 2.49 KB
/
listRatings.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
<!DOCTYPE html>
<?php
$currentpage="List Ratings";
$customer = $_GET['cust'];
$drink = $_GET['drink'];
$shop = $_GET['shop'];
?>
<html>
<head>
<title>List Parts</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<?php
// change the value of $dbuser and $dbpass to your username and password
include 'connectvars.php';
include 'header.php';
echo"<div class=\"mainbody\">";
// Connect to the database
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
// query to select all information from parts table
$query = "SELECT Shop.Name, Drink.Flavor, Rating.Comment, Rating.NumStars, Customers.Name AS CustName
FROM `Rating`, `Customers`, `Drink`, `Shop`
WHERE Rating.CustomerID = Customers.CustomerID
AND Rating.DrinkID = Drink.DrinkID
AND Drink.ShopID = Shop.ShopID
AND Rating.DrinkID = $drink";
// Get results from query
$result = mysqli_query($conn, $query);
if (!$result) {
die("Query to show fields from table failed");
}
// If there are parts in the database construct an HTML table
// to display the results
$row = mysqli_fetch_array($result);
if(mysqli_num_rows($result) > 0){
echo "<h2> Shop:" . $row['Name']. "</h1>";
echo "<h2> Drink:" . $row['Flavor']. "</h1>";
echo "<table id='t01' border='1'>";
// Create the table header
echo "<thead>";
echo "<tr>";
echo "<th>Customer</th>";
echo "<th>Comment</th>";
echo "<th>Rating(1-5)</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
// Extract rows from the results returned from the database
mysqli_data_seek($result, 0);
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['CustName'] . "</td>";
echo "<td>" . $row['Comment'] . "</td>";
echo "<td>" . $row['NumStars'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
// Close the database connection
mysqli_close($conn);
echo "<input id=\"addButton\" type=\"Button\" value=\"Add a Rating\" onclick=\"window.location='addRating?user=".$user."&shop=".$shop."&drink=".$drink."'\">";
echo "<input id=\"addButton\" type=\"Button\" value=\"Go Back to All Drinks\" onclick=\"window.location='list_drinks?user=".$user."&shop=".$shop."'\">";
?>
</div>
</body>
</html>