id = $id; $this->subject = $row['thread_subject']; $this->date_created = $row['thread_date_created']; $this->date_lastpost = $row['thread_date_lastpost']; $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); return 1; } 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_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) { $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; }