diff options
Diffstat (limited to 'topic.php')
-rw-r--r-- | topic.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/topic.php b/topic.php new file mode 100644 index 0000000..216211f --- /dev/null +++ b/topic.php @@ -0,0 +1,57 @@ +<?php + +include_once 'header.php'; +include_once 'includes/db_inc.php'; + +$sql = "SELECT topic_id, topic_subject, topic_date, user_id, user_name FROM topics LEFT JOIN users ON topic_author = user_id WHERE topic_id = " . mysqli_real_escape_string($dbc, $_GET['id']); +$result = mysqli_query($dbc, $sql); + +if (!$result) { + die('Error trying to display topic page: ' . mysqli_error()); +} + +if (mysqli_num_rows($result) == 0) { + echo 'This topic does not exist'; +} else { + while ($row = mysqli_fetch_assoc($result)) { + echo '<section><h1>' . $row['topic_subject'] . '</h1>'; + echo 'Created by <b>' . $row['user_name'] . '</b> on ' . date('M d, Y', strtotime($row['topic_date'])) . '</section>'; + $topic_id = $row['topic_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_topic = " . 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 topic 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>'; + + echo ' +<section> +<form action="includes/reply_inc.php?reply_to=' . $topic_id . '" method="post"> + <h2>Reply to this thread</h2> + <textarea name="reply_content"></textarea> + <br> + <input type="submit" name="submit"> +</form> +</section>'; +} + +mysqli_free_result($result); + +include 'footer.php';
\ No newline at end of file |