-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview-all.php
More file actions
67 lines (62 loc) · 2.15 KB
/
Copy pathview-all.php
File metadata and controls
67 lines (62 loc) · 2.15 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
<?php
require 'lib/common.php';
try {
$pdo = connectDatabase();
$stmt = $pdo->query("
SELECT p.id, p.title, p.body, p.created_at, u.username
FROM post p
JOIN user u ON p.user_id = u.id
ORDER BY p.created_at DESC
");
$posts = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {
error_log('Error: ' . $e->getMessage());
echo '<p>Error: ' . escapeHtml($e->getMessage()) . '</p>';
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>All Blog Posts</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; background-color: #f4f4f4; }
header, footer { text-align: center; margin-bottom: 20px; }
.post { border-bottom: 1px solid #ccc; padding: 10px 0; background-color: white; border-radius: 4px; margin-bottom: 15px; box-shadow: 0 1px 5px rgba(0,0,0,0.1); }
.post h2 { margin: 0; color: #333; }
.post-snippet { margin: 10px 0; color: #555; }
</style>
</head>
<body>
<header>
<?php
if (file_exists('templates/title.php')) {
require 'templates/title.php';
} else {
echo '<h1>All Blog Posts</h1>';
}
?>
</header>
<main>
<?php if (empty($posts)): ?>
<p>No posts found.</p>
<?php else: ?>
<?php foreach ($posts as $row): ?>
<article class="post">
<h2><?php echo escapeHtml($row['title']); ?></h2>
<div><em>Published by <?php echo escapeHtml($row['username']); ?> on <?php echo convertSqlDate($row['created_at']); ?></em></div>
<p class="post-snippet">
<?php echo nl2br(escapeHtml(substr($row['body'], 0, 100))) . '...'; ?>
</p>
<p><a href="view-post.php?id=<?php echo $row['id']; ?>">Read more...</a></p>
</article>
<?php endforeach; ?>
<?php endif; ?>
</main>
<footer>
© <?php echo date("Y"); ?> My Blog. All rights reserved.
</footer>
</body>
</html>