-
Notifications
You must be signed in to change notification settings - Fork 0
/
showPictures.php
60 lines (57 loc) · 1.45 KB
/
showPictures.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
<?php
/**********************************************************
* File: showPictures.php
* Author: James Richter
*
* Description: Our main home page. It shows all of the
* pictures in our database, starting with the most recent.
*
***********************************************************/
session_start();
include "showLoginBar.php";
include "loadPicDatabase.php";
// User is a guest by default.
if (!isset($_SESSION["username"]))
{
$_SESSION["username"] = guest;
}
?>
<!DOCTYPE html>
<html>
<title>Pictures</title>
<body>
<?php
showLoginBar();
// This will retrieve images from the database
function getPicSite($id) {
$conn = loadDatabase();
try {
$sql = 'SELECT * FROM picture';
$stmt = $conn->prepare($sql);
$stmt->execute();
$data = $stmt->fetchAll();
$stmt->closeCursor();
} catch (PDOException $ex) {
echo 'PDO error in model.';
}
if (is_array($data)) {
return $data;
} else {
return FALSE;
}
}
// Display all of the pictures in turn.
$test = getPicSite(1);
echo "<h1>Recent Pictures</h1>";
foreach (array_reverse($test) as $key => $value) {
echo " " .
$value['title'] .
"<a href=\"dynamic_page.php?id=" .
$value['pictureID'] .
"\"><img src=\"" .
$value['image'] .
"\" height=\"200\"></a>";
}
?>
</body>
</html>