-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.php
59 lines (53 loc) · 1.8 KB
/
common.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
<?php include("top.html"); ?>
<!--
Shahria Kazi, CSE 190M, Section MK, TA: Tyler Rigsby, May 2nd, 2012
This page contains common code that are shared between both the film search pages.
It also contains functions that captures common code that displays the films of a given actor.
-->
<?php
$firstname = $_GET["firstname"];
$lastname = $_GET["lastname"];
$imdb = new PDO("mysql:dbname=imdb;host=localhost", "wastar09", "2xgL2Mx9fdtDU");
$fname = $imdb->quote($firstname);
$lname = $imdb->quote($lastname);
# Query that searches for a actor given the last name
# exactly and firstname starting with the letters that the user types.
# If more than one actor with the identical lastnames exists
# then the one with the highest film counts gets chosen and returns that actors id
$search_actor = $imdb->query("SELECT id
FROM actors
WHERE first_name LIKE '$firstname%' AND last_name = $lname
ORDER BY film_count DESC
LIMIT 1;");
$actor_id = $search_actor->fetchcolumn();
$actor_not_found = "Actor $firstname $lastname not found.";
# this function takes a firstname, lastname and a long string as parameters
# displays that string inside a paragraph
function exists($firstname, $lastname, $string) { ?>
<p>
<?= $string; ?>
</p>
<?php }
# This function takes an array and an incrementor
# as parameters and loops over the array and displays
# the film title and year in a table
function displayTable($rows, $firstname, $lastname, $caption) { ?>
<h1>Results for <?= $firstname; ?> <?= $lastname; ?></h1>
<table>
<caption><?= $caption; ?></caption>
<tr>
<th>#</th>
<th>Title</th>
<th>Year</th>
</tr>
<?php
$i = 1;
foreach($rows as $row) { ?>
<tr>
<td><?= $i++; ?></td>
<td><?= $row["name"]; ?></td>
<td><?= $row["year"]; ?></td>
</tr>
<?php } ?>
</table>
<?php } ?>