-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.php
More file actions
49 lines (43 loc) · 1.63 KB
/
post.php
File metadata and controls
49 lines (43 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
<?php
include 'partials/header.php';
// fetch post from database if id is set
if(isset($_GET['id'])) {
$id = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
$query = "SELECT * FROM posts WHERE id=$id";
$result = mysqli_query($connection, $query);
$post = mysqli_fetch_assoc($result);
} else {
header('Location:'. ROOT_URL .'blog.php');
}
?>
<section class="singlepost">
<div class="container singlepost__container">
<h2><?= $post['title']?></h2>
<div class="post__author">
<?php
// fetch category from categories table using category id
$author_id = $post['author_id'];
$author_query = "SELECT * FROM users WHERE id=$author_id";
$author_result = mysqli_query($connection, $author_query);
$author = mysqli_fetch_array($author_result);
?>
<div class="post__author-avatar">
<img src="./images/<?= $author['avatar'] ?>">
</div>
<div class="post__author-info">
<h5>By: <?= "{$author['firstname']} {$author['lastname']}" ?></h5>
<small><?= date("M d, Y - H:i", strtotime($post['date_time'])) ?></small>
</div>
</div>
<div class="singlepost__thumbnail">
<img src="./images/<?= $post['thumbnail'] ?>">
</div>
<p>
<?= $post['body'] ?>
</p>
</div>
</section>
<!--======================= END OF SINGLE POST ==========================-->
<?php
include 'partials/footer.php';
?>