summaryrefslogtreecommitdiff
path: root/topic.php
diff options
context:
space:
mode:
authorCflip <36554078+cflip@users.noreply.github.com>2021-01-22 20:45:43 -0700
committerCflip <36554078+cflip@users.noreply.github.com>2021-01-22 20:45:43 -0700
commitdf49a36e140acc211fdc31480d40281404110310 (patch)
tree3a25af561ed3703ad5df8cf90d9f56d8824f7a4f /topic.php
Inital commit with existing code
Diffstat (limited to 'topic.php')
-rw-r--r--topic.php57
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