-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposts.php
More file actions
34 lines (32 loc) · 1.11 KB
/
posts.php
File metadata and controls
34 lines (32 loc) · 1.11 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
<?php include "includes/header.php"; ?>
<?php
//Create db object
$db = new Database();
//Check URL category
if (isset($_GET['category'])) {
$category = $_GET['category'];
$query = "SELECT * FROM posts WHERE category = " . $category . " ORDER BY id DESC";
$posts = $db->select($query);
} else {
// db query
$query = "SELECT * FROM posts ORDER BY id DESC";
// Run db query
$posts = $db->select($query);
}
// db query - categories
$query = "SELECT * FROM categories";
// Run db query
$categories = $db->select($query);
?>
<?php if($posts) : ?>
<?php while($row = $posts->fetch_assoc()) : ?>
<h3><?php echo $row['title']; ?></h3>
<p><?php echo shortenText($row['body']); ?></p>
<a href="post.php?id=<?php echo urlencode($row['id']); ?>" class="button">Read More</a>
<p class="u-pull-right"><small>Written by <?php echo $row['author']; ?> on <?php echo formatDate($row['date']); ?></small></p>
<hr>
<?php endwhile; ?>
<?php else : ?>
<p>My apologies. There aren't any posts.</p>
<?php endif; ?>
<?php include "includes/footer.php"; ?>