diff options
author | Cflip <36554078+cflip@users.noreply.github.com> | 2021-01-23 12:25:51 -0700 |
---|---|---|
committer | Cflip <36554078+cflip@users.noreply.github.com> | 2021-01-23 12:26:18 -0700 |
commit | 279d399461e6a66157bb2f0bc8209bf0fcb36c9c (patch) | |
tree | 779492cc411d6c9171d57cdecf7a43f39e2ca512 /thread.php | |
parent | 0b26a9cd485d5b1ed509d9da998780d8b658eb8a (diff) |
Change terminology from topics to threads
Diffstat (limited to 'thread.php')
-rw-r--r-- | thread.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/thread.php b/thread.php new file mode 100644 index 0000000..52ad8b3 --- /dev/null +++ b/thread.php @@ -0,0 +1,67 @@ +<?php include_once 'header.php'; ?> + +<?php +include_once 'includes/db_inc.php'; + +$sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name FROM threads LEFT JOIN users ON thread_author = user_id WHERE thread_id = " . mysqli_real_escape_string($dbc, $_GET['id']); +$result = mysqli_query($dbc, $sql); + +if (!$result) { + die('Error trying to display thread page: ' . mysqli_error($dbc)); +} + +if (mysqli_num_rows($result) == 0) { + echo 'This thread does not exist'; +} else { + while ($row = mysqli_fetch_assoc($result)) { + echo '<section><h1>' . $row['thread_subject'] . '</h1>'; + echo 'Created by <b>' . $row['user_name'] . '</b> on ' . date('M d, Y', strtotime($row['thread_date'])) . '</section>'; + $thread_id = $row['thread_id']; + } +} + +echo '</section>'; + +mysqli_free_result($result); + +$sql = "SELECT post_content, post_date, post_author, user_id, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_thread = " . mysqli_real_escape_string($dbc, $_GET['id']); +$result = mysqli_query($dbc, $sql); + +if (!$result) { + die('Error trying to display posts: ' . mysqli_error($dbc)); +} + +if (mysqli_num_rows($result) == 0) { + echo '<section>This thread has no posts</section>'; +} else { + echo '<table>'; + while ($row = mysqli_fetch_assoc($result)) { + echo '<tr class="post"><td class="right">Posted by <b>' . $row['user_name'] . '</b><br><small>' . date('m/d/Y g:ia', strtotime($row['post_date'])) . '</small></td>'; + echo '<td class="left">' . $row['post_content'] . '</td></tr>'; + } + echo '</table>'; +} + +mysqli_free_result($result); + +if (isset($_SESSION['signed_in'])) { + echo ' + <section> + <form action="includes/reply_inc.php?reply_to=' . $thread_id .'" method="post"> + <h2>Reply to this thread</h2> + <textarea name="reply_content"></textarea> + <br> + <input type="submit" name="submit"> + </form> + </section> + '; +} else { + echo ' + <section> + <a href="signin.php">Sign in</a> to reply to this thread</a> + </section> + '; +} + +include_once 'footer.php'; +?>
\ No newline at end of file |