'; $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 '

' . $row['cat_name'] . '

'; echo $row['cat_description']; } } mysqli_free_result($result); echo ''; $sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name FROM threads JOIN users ON thread_author = user_id WHERE thread_cat = " . mysqli_real_escape_string($dbc, $_GET['id']) . " ORDER BY thread_id DESC"; $result = mysqli_query($dbc, $sql); if (!$result) { die('Error trying to display threads: ' . mysqli_error($dbc)); } echo ''; $sql = "SELECT post_id, post_date, user_id, user_name FROM posts JOIN users ON post_author = user_id WHERE post_thread = ? ORDER BY post_id DESC LIMIT 1"; $stmt = mysqli_stmt_init($dbc); if (!mysqli_stmt_prepare($stmt, $sql)) { die('Could not create thread due to internal error: ' . mysqli_error($dbc)); } while ($row = mysqli_fetch_assoc($result)) { mysqli_stmt_bind_param($stmt, "i", $row['thread_id']); mysqli_stmt_execute($stmt); $thread_res = mysqli_stmt_get_result($stmt); $thread = mysqli_fetch_assoc($thread_res); echo ''; } mysqli_stmt_close($stmt); mysqli_free_result($result); echo '
ThreadLatest Post
'; echo '

' . $row['thread_subject'] . '

'; echo 'by ' . $row['user_name'] . ' on ' . date('M d, Y', strtotime($row['thread_date'])) . ''; echo '
by ' . $thread['user_name'] . '
'; echo '' . date('m/d/Y g:ia', strtotime($thread['post_date'])) . '
'; include 'footer.php';