-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestingDatabase.php
More file actions
74 lines (63 loc) · 1.63 KB
/
Copy pathtestingDatabase.php
File metadata and controls
74 lines (63 loc) · 1.63 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Blah</title>
<style>
body {
background-image: url('http://4.bp.blogspot.com/-HTvSYzA-pO4/UgQb4Zh_u0I/AAAAAAAAEuI/XwhtogT_1tA/s1600/3+cute2.jpg');
background-repeat: no-repeat;
background-size: cover;
}
td:nth-child(even){
background-color: #cccccc;
color: #000000;
width: 400px;
}
td:nth-child(odd) {
width: 50px;
}
</style>
</head>
<body>
<table style="border: 1px solid black;">
<tr><th>ID</th><th>Title</th></tr>
<?php
// Table class to make things pretty
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='text-align: center;
border: 1px solid black;'>"
. parent::current() . "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>";
}
}
$servername = "localhost";
$dbname = "gan1832";
$username = "gan1832";
$password = "sleepyOwl12";
try {
$conn = new PDO("mysql:host=$servername; dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT movieID, title FROM movies");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error!: " . $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
</table>
</body>
</html>