diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/Category.php | 22 | ||||
-rw-r--r-- | model/Thread.php | 22 |
2 files changed, 44 insertions, 0 deletions
diff --git a/model/Category.php b/model/Category.php index ffd903c..4e57f46 100644 --- a/model/Category.php +++ b/model/Category.php @@ -54,6 +54,28 @@ class Category { mysqli_free_result($result); return $threads; } + + function get_latest_thread($dbc) { + $sql = "SELECT thread_id FROM threads WHERE thread_category = " . $this->id . " ORDER BY thread_date_lastpost DESC LIMIT 1"; + $result = mysqli_query($dbc, $sql); + + if (!$result) { + echo 'Could not get thread from category: ' . mysqli_error($dbc); + } + + $thread = null; + + if (mysqli_num_rows($result) == 0) { + } else { + while ($row = mysqli_fetch_assoc($result)) { + $thread = new Thread(); + $thread->get_from_database($row['thread_id'], $dbc); + } + } + + mysqli_free_result($result); + return $thread; + } } function get_all_categories($dbc) { 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) { |