diff options
author | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-21 17:29:58 -0600 |
---|---|---|
committer | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-21 17:29:58 -0600 |
commit | 7ef208fc1ae5a24d7b3cd2e22e969285fbf7262a (patch) | |
tree | 7995fdce15426408ea1f893c6842dc63cd2b2fae /model/Thread.php | |
parent | d0e23fd32cd2c968bdb905604c543b8c1bb8f6ee (diff) |
Add additional classes and functions
Diffstat (limited to 'model/Thread.php')
-rw-r--r-- | model/Thread.php | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/model/Thread.php b/model/Thread.php index 78d2614..ade24b5 100644 --- a/model/Thread.php +++ b/model/Thread.php @@ -1,6 +1,8 @@ <?php include_once 'Category.php'; +include_once 'User.php'; +include_once 'Post.php'; class Thread { public $id = 0; @@ -11,7 +13,7 @@ class Thread { public $author; function get_from_database($id, $dbc) { - $sql = "SELECT thread_subject, thread_date_created, thread_date_lastpost, thread_category FROM threads WHERE thread_id = " . mysqli_real_escape_string($dbc, $id); + $sql = "SELECT thread_subject, thread_date_created, thread_date_lastpost, thread_category, thread_author FROM threads WHERE thread_id = " . mysqli_real_escape_string($dbc, $id); $result = mysqli_query($dbc, $sql); if (!$result) { @@ -29,7 +31,58 @@ class Thread { $this->category = new Category(); $this->category->get_from_database($row['thread_category'], $dbc); + + $this->author = new User(); + $this->author->get_by_id($row['thread_author'], $dbc); + } + } + + mysqli_free_result($result); + } + + function get_posts($dbc) { + $sql = "SELECT post_id FROM posts WHERE post_thread = " . $this->id; + $result = mysqli_query($dbc, $sql); + + if (!$result) { + echo 'Could not get posts from thread: ' . mysqli_error($dbc); + } + + $posts = array(); + + if (mysqli_num_rows($result) == 0) { + } else { + while ($row = mysqli_fetch_assoc($result)) { + $post = new Post(); + $post->get_from_database($row['post_id'], $dbc); + array_push($posts, $post); } } + + mysqli_free_result($result); + return $posts; + } +} + +function get_all_threads($dbc) { + $sql = "SELECT thread_id FROM threads"; + $result = mysqli_query($dbc, $sql); + + if (!$result) { + echo 'Failed to get threads: ' . mysqli_error($dbc); + } + + $threads = array(); + + if (mysqli_num_rows($result) == 0) { + } else { + while ($row = mysqli_fetch_assoc($result)) { + $thread = new Thread(); + $thread->get_from_database($row['thread_id'], $dbc); + array_push($threads, $thread); + } } + + mysqli_free_result($result); + return $threads; }
\ No newline at end of file |