-
Notifications
You must be signed in to change notification settings - Fork 0
/
task6.txt
198 lines (165 loc) · 8.19 KB
/
task6.txt
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<head>
<title>Assignment3</title>
</head>
<body>
<?php include 'menu.inc';
$servername = "localhost";
$username = "root";
$password = "";
$conn = new PDO("mysql:host=$servername;dbname=films", $username, $password);
$results = $conn->query('Select * from actors');
if(!$results){
print "<p>Could not retrieve Actors list: " . $conn->errorMsg(). "</p>";
}
echo "<br/><b>Actor's table</b>:";
echo "<table style='width:100%'><tr><th>Actor id</th><th>Name</th><th>Notes</th></tr>";
while ($row = $results->fetch()) {
echo "<tr>";
echo "<td>".$row['ActorID']."</td>";
echo "<td>".$row['ActorFullName']."</td>";
echo "<td>".$row['ActorNotes']."</td>";
echo "</tr>";
echo "<br/>";
}
echo "</table>";
$conn = new PDO("mysql:host=$servername;dbname=films", $username, $password);
$results = $conn->query('Select * from roletypes');
echo "<br/><b>Roles table</b>:";
echo "<table style='width:100%'><tr><th>Type id</th><th>Type</th></tr>";
while ($row = $results->fetch()) {
echo "<tr>";
echo "<td>".$row['RoleTypeID']."</td>";
echo "<td>".$row['RoleType']."</td>";
echo "</tr>";
echo "<br/>";
}
echo "</table>";
$conn = new PDO("mysql:host=$servername;dbname=films", $username, $password);
$results = $conn->query('Select * from FilmActorRoles');
echo "<br/><b>Film-Actor-Roles table</b>:";
echo "<table style='width:100%'><tr><th>Film Title id</th><th>Actor id</th><th>Role Type id</th><th>Charecter Name</th><th>Charecter Description</th></tr>";
while ($row = $results->fetch()) {
echo "<tr>";
echo "<td>".$row['FilmTitleID']."</td>";
echo "<td>".$row['ActorID']."</td>";
echo "<td>".$row['RoleTypeID']."</td>";
echo "<td>".$row['CharecterName']."</td>";
echo "<td>".$row['CharecterDescription']."</td>";
echo "</tr>";
echo "<br/>";
}
echo "</table>";
$conn = new PDO("mysql:host=$servername;dbname=films", $username, $password);
$results = $conn->query('Select * from FilmTitles');
echo "<br/><b>Film Titles Table</b>:";
echo "<table style='width:100%'><tr><th>Film Title ID</th><th>Film Title</th><th>Film Duration</th><th>Film Story</th></tr>";
while ($row = $results->fetch()) {
echo "<tr>";
echo "<td>".$row['FilmTitleID']."</td>";
echo "<td>".$row['FilmTitle']."</td>";
echo "<td>".$row['FilmDuration']."</td>";
echo "<td>".$row['FilmStory']."</td>";
echo "</tr>";
echo "<br/>";
}
echo "</table>";
echo '<br/><form action="task6.php" method="POST">
<b>Choose Query clause:</b><br/>
<p><input type="radio" name="query"
value="order">Order By</p>
<p><input type="radio" name="query"
value="like">Like Operator</>
<p><input type="radio" name="query"
value="inner">Inner Join</p>
<p><input type="radio" name="query"
value="where">WHERE clause and AND operator</p>
<p><input type="radio" name="query"
value="avg">AVG function</p>
<input type="submit" name="submit">
</form>';
if(isset($_POST['submit'])){
if (isset($_POST['query'])) {
$queryType = $_POST['query'];
switch ($queryType) {
case 'order':
$results = $conn->query('Select * from Actors order by ActorFullName');
echo "<br/><b>Actor's table</b>:";
echo "<table><tr><th>Actor id</th><th>Name</th><th>Notes</th></tr>";
while ($row = $results->fetch()) {
echo "<tr>";
echo "<td>".$row['ActorID']."</td>";
echo "<td>".$row['ActorFullName']."</td>";
echo "<td>".$row['ActorNotes']."</td>";
echo "</tr>";
echo "<br/>";
}
echo "</table>";
break;
case 'like':
$results = $conn->query('Select * from Actors WHERE ActorFullName Like "%n"');
echo "<br/><b>Actors whose names end with an 'n'</b>:";
echo "<table><tr><th>Actor id</th><th>Name</th><th>Notes</th></tr>";
while ($row = $results->fetch()) {
echo "<tr>";
echo "<td>".$row['ActorID']."</td>";
echo "<td>".$row['ActorFullName']."</td>";
echo "<td>".$row['ActorNotes']."</td>";
echo "</tr>";
echo "<br/>";
}
echo "</table>";
break;
case 'inner':
$results = $conn->query('SELECT a.ActorFullName,fa.CharecterName,ft.filmtitle
FROM actors a, filmactorroles fa, filmtitles ft
WHERE a.ActorID=fa.ActorID
AND fa.FilmTitleID=ft.FilmTitleID');
echo "<br/><b>Actors, their charecter and films</b>:";
echo "<table><tr><th>Actor Name</th><th>Charecter Name</th><th>Film name</th></tr>";
while ($row = $results->fetch()) {
echo "<tr>";
echo "<td>".$row['ActorFullName']."</td>";
echo "<td>".$row['CharecterName']."</td>";
echo "<td>".$row['filmtitle']."</td>";
echo "</tr>";
echo "<br/>";
}
echo "</table>";
break;
case 'where':
$results = $conn->query('SELECT * FROM `actors` WHERE ActorFullName="Jonathan Davis"');
echo "<br/><b>Actor with the name 'Jonathan Davis'</b>:";
echo "<table><tr><th>Actor ID</th><th>Full name</th><th>Notes</th></tr>";
while ($row = $results->fetch()) {
echo "<tr>";
echo "<td>".$row['ActorID']."</td>";
echo "<td>".$row['ActorFullName']."</td>";
echo "<td>".$row['ActorNotes']."</td>";
echo "</tr>";
echo "<br/>";
}
echo "</table>";
default:
# code...
$results = $conn->query('SELECT SEC_TO_TIME(AVG(TIME_TO_SEC("FilmDuration"))) AS Average FROM filmtitles');
echo "<br/><b>Average seconds'</b>:";
echo "<table><tr><th>Average</th></tr>";
while ($row = $results->fetch()) {
echo "<tr>";
echo "<td>".$row['Average']."</td>";
echo "</tr>";
echo "<br/>";
}
echo "</table>";
break;
}
}else {
echo 'Select the type of query!!';
}
}
?>
<iframe src="task5.txt" height="400" width="1200">
Your browser does not support iframes. </iframe>
</body>
</html>