-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoviereportbygenre.php
68 lines (58 loc) · 1.98 KB
/
moviereportbygenre.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
<html>
<body>
<button onclick="history.go(-1);">Back </button><br>
<?php
echo "<h1>MOVIE REPORT BY Genre</h1><br>";
$servername = "Yourserver";
$username = "Youruser";
$password = "Yourpassword";
$dbname = "Yourdatabase";
$tempgid= 0 ;// temp year minimum
$tempgidend = 0 ;
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//insert into table
// prepare sql and bind parameters
$getgid = $conn-> prepare ("select MIN(gid), MAX(gid) from genre");
$getgid-> execute();
while( $yearrow = $getgid->fetch(PDO::FETCH_ASSOC) )
{
$tempgid =$yearrow['MIN(gid)'];
$tempgidend = $yearrow['MAX(gid)'];
}
while ($tempgid <= $tempgidend)
{
$getgname = $conn-> prepare ("select gname from genre where genre.gid=:tgid");
$getgname->bindParam(':tgid', $tempgid);
$getgname-> execute();
while( $yearrow = $getgname->fetch(PDO::FETCH_ASSOC) )
{
echo $yearrow['gname'];
}
$stmt = $conn->prepare("select movie.title, movie.rating, actor.fname, actor.lname
from movie, genre, role, actor
where movie.gid=genre.gid and role.mid=movie.mid and role.aid=actor.aid and genre.gid= :tempgid");
$stmt->bindParam(':tempgid', $tempgid);
// insert a row
$stmt->execute();
$temptitle = '';
foreach ($stmt->fetchAll() as $row)
{
if ($temptitle == $row['title'])
{
print ','. $row ['fname'] .' ' . $row ['lname'] ;
}
else
{
print '<br /> ' . $row['title'] . '('. $row['rating'] .')'. $row['gname'] . '['. $row ['fname'] .' ' . $row ['lname'];
$temptitle = $row['title'];
}
}
echo "<br><br>";
$tempgid= $tempgid + 1;
}
$conn = null;
?>
</body>
</html>