diff options
Diffstat (limited to 'category.php')
-rw-r--r-- | category.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/category.php b/category.php new file mode 100644 index 0000000..4e10444 --- /dev/null +++ b/category.php @@ -0,0 +1,49 @@ +<?php + +include_once 'includes/db_inc.php'; +include_once 'header.php'; + +echo '<section>'; + +$sql = "SELECT cat_name, cat_description FROM categories WHERE cat_id = " . mysqli_real_escape_string($dbc, $_GET['id']); +$result = mysqli_query($dbc, $sql); + +if (!$result) { + die('Error trying to display category: ' . mysqli_error($dbc)); +} + +// Display category name and description + +if (mysqli_num_rows($result) == 0) { + echo 'This category does not exist'; +} else { + while ($row = mysqli_fetch_assoc($result)) { + echo '<h1>' . $row['cat_name'] . '</h1>'; + echo $row['cat_description']; + } +} + +mysqli_free_result($result); + +echo '</section>'; + +$sql = "SELECT topic_id, topic_subject, topic_date, user_name FROM topics LEFT JOIN users ON topic_author = user_id WHERE topic_cat = " . mysqli_real_escape_string($dbc, $_GET['id']); +$result = mysqli_query($dbc, $sql); + +if (!$result) { + die('Error trying to display topics: ' . mysqli_error($dbc)); +} + +// Display table of posts + +echo '<table><tr><th class="left">Topic</th><th class="right">Latest Post</th></tr>'; + +while ($row = mysqli_fetch_assoc($result)) { + echo '<tr><td class="left">'; + echo '<h4><a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a></h4>'; + echo '<small>by <b>' . $row['user_name'] . '</b> on ' . date('M d, Y', strtotime($row['topic_date'])) . '</small></td><td class="right">24 replies</td></tr>'; +} + +echo '</table>'; + +include 'footer.php';
\ No newline at end of file |