From c9732788143886b611cb2fecfb53daf3d8add48f Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Wed, 24 Mar 2021 18:29:41 -0600 Subject: Show latest thread/post on pages --- model/Thread.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'model/Thread.php') diff --git a/model/Thread.php b/model/Thread.php index ade24b5..20c6c0a 100644 --- a/model/Thread.php +++ b/model/Thread.php @@ -62,6 +62,28 @@ class Thread { mysqli_free_result($result); return $posts; } + + function get_latest_post($dbc) { + $sql = "SELECT post_id FROM posts WHERE post_thread = " . $this->id . " ORDER BY post_date DESC LIMIT 1"; + $result = mysqli_query($dbc, $sql); + + if (!$result) { + echo 'Could not get post from category: ' . mysqli_error($dbc); + } + + $post = null; + + if (mysqli_num_rows($result) == 0) { + } else { + while ($row = mysqli_fetch_assoc($result)) { + $post = new Post(); + $post->get_from_database($row['post_id'], $dbc); + } + } + + mysqli_free_result($result); + return $post; + } } function get_all_threads($dbc) { -- cgit v1.2.3