-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber4.php
More file actions
43 lines (41 loc) · 1.27 KB
/
Number4.php
File metadata and controls
43 lines (41 loc) · 1.27 KB
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
<?php
ini_set ('error_reporting', 1);
try{
require_once('/Users/zachdevore/UNCW/Spring2026/Database Design/final_project_frontend/pdo_connect.php');
$sql = "SELECT MPArating AS 'MPA Rating',
COUNT(MovieID) AS 'Number of Movies',
ROUND(AVG(IMDbRating),1) AS 'Avg IMDb Rating'
FROM CSC355SP26Movies.Movie
GROUP BY MPArating
HAVING COUNT(MovieID)>1
ORDER BY COUNT(MovieID) DESC";
$result = $dbc-> query($sql);
} catch (PDOException $e){
echo $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Aggregate Function using GROUP BY and HAVING</title>
<meta charset ="utf-8">
</head>
<body>
<h2>Aggregate Function using GROUP BY and HAVING</h2>
<table>
<tr>
<th>MPA Rating</th>
<th>Number of Movies</th>
<th>Avg IMDb Rating</th>
</tr>
<?php foreach ($result as $row) {
echo "<tr>";
echo "<td>".$row['MPA Rating']."</td>";
echo "<td>".$row['Number of Movies']."</td>";
echo "<td>".$row['Avg IMDb Rating']."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>