<?php require_once "ffa-data/main.php"; require_once "ffa-data/header.php"; //Get page from GET if GET isn't empty $page = !empty($_GET['page']) ? (int) $_GET['page'] : 1; $id = $_GET['id']; $postP1 = ($page - 1) * $postPerPage; $postP2 = $page * $postPerPage; $bbcode = new Golonka\BBCode\BBCodeParser(); $database->makeQuery("SELECT * FROM topic WHERE id = ?;"); $database->bind(1, $id, PDO::PARAM_INT); $database->executeHandle(); $result = $database->returnResult(); $database->clean(); // Set $topic to "none" if $result is empty // If $result isn't empty, set $topic to $result[0] $topic = empty($result) ? "none" : $result[0]; $comment = "none"; if ($topic != "none") { $database->makeQuery("SELECT * FROM users WHERE id = ?;"); $database->bind(1, $topic["author_id"], PDO::PARAM_INT); $database->executeHandle(); $result = $database->returnResult(); $database->clean(); $topic["author_name"] = $result[0]["name"]; $topic["content_parsed"] = $bbcode->parse($topic["content"]); $database->makeQuery("SELECT * FROM comments WHERE topic_id = ?;"); $database->bind(1, $id, PDO::PARAM_INT); $database->executeHandle(); $result = $database->returnResult();
<?php include_once 'include/header.php'; include_once 'include/helpers.php'; $bbcode = new Golonka\BBCode\BBCodeParser(); $topic = array(); $comments = array(); $result = $connection->query('SELECT * FROM topic WHERE id = ' . $connection->real_escape_string($_GET['id']) . ' ORDER BY id ASC;'); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $topic[$row['id']] = $row; $topic[$row['id']]['content'] = $bbcode->parseCaseInsensitive($row['content']); $topic[$row['id']]['raw_content'] = javascript_escape($row['content']); $result2 = $connection->query('SELECT * FROM users WHERE id = ' . $row['author_id']); if ($result2->num_rows > 0) { while ($row2 = $result2->fetch_assoc()) { $topic[$row['id']]['author_name'] = $row2['name']; $topic[$row['id']]['author_name_safe'] = javascript_escape($row2['name']); } } $result2 = $connection->query('SELECT * FROM category WHERE id = ' . $row['category_id']); if ($result2->num_rows > 0) { while ($row2 = $result2->fetch_assoc()) { $topic[$row['id']]['category_name'] = $row2['name']; } } $result2 = $connection->query('SELECT * FROM comments WHERE topic_id = ' . $row['id']); if ($result2->num_rows > 0) { while ($row2 = $result2->fetch_assoc()) { $comments[$row2['id']] = $row2; $comments[$row2['id']]['content'] = $bbcode->parseCaseInsensitive(nl2br($row2['content']));
<?php if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } include_once 'include/header.php'; $bbcode = new Golonka\BBCode\BBCodeParser(); $result = $connection->query('SELECT id FROM topic WHERE category_id = ' . $connection->real_escape_string($_GET['id'])); if (false === $result) { throw new Exception('Query failed with: ' . $connection->error); } else { $row_count = mysqli_num_rows($result); // free the result set as you don't need it anymore mysqli_free_result($result); } $page_count = 0; if (0 === $row_count) { // maybe show some error since there is nothing in your table } else { // determine page_count $page_count = (int) ceil($row_count / PAGE_LIMIT); // double check that request page is in range if ($page > $page_count) { // error to user, maybe set page to 1 $page = 1; } } $result = $connection->query('SELECT * FROM category WHERE id = ' . $connection->real_escape_string($_GET['id']) . ';'); if ($result->num_rows > 0) {