An unexpected error occurred while fetching mods.
"; } else { $countStatement->bind_param('i', $categoryData['id']); $countStatement->execute(); $countResult = $countStatement->get_result(); if (!$countResult) { echo "An unexpected error occurred while fetching mods.
"; $countStatement->close(); } else { $countRow = $countResult->fetch_assoc(); $countStatement->close(); if (!$countRow) { echo "An unexpected error occurred while fetching mods.
"; } else { $modCount = $countRow['count']; $totalPages = ceil($modCount / PAGE_MODS); $statement = $connection->prepare('SELECT mods.id AS id, mods.name AS name, mods.slug AS slug, mods.description AS description, mods.image_ext AS image_ext, mods.is_paid AS is_paid, users.username AS user, users.id AS user_id, AVG(reviews.rating) AS rating, COUNT(reviews.id) AS reviews FROM mods LEFT JOIN categories ON categories.id = mods.category LEFT JOIN ( SELECT reviews.rating AS rating, reviews.id AS id, reviews.mod AS `mod` FROM reviews JOIN users ON users.id = reviews.user AND users.is_verified = 1 AND users.is_deleted = 0 AND users.is_suspended = 0 ) AS reviews ON reviews.mod = mods.id JOIN users ON users.id = mods.user WHERE categories.id = ? AND mods.is_removed = 0 AND users.is_suspended = 0 AND users.is_deleted = 0 AND users.is_verified = 1 GROUP BY mods.id ORDER BY IFNULL(rating, 0) DESC, reviews DESC LIMIT ?,?;'); if (!$statement) { echo "An unexpected error occurred while fetching mods.
"; } else { $pageNumber = isset($_GET['page']) && filter_var($_GET['page'], FILTER_VALIDATE_INT) ? intval($_GET['page']) : 1; $firstNumber = PAGE_MODS * ($pageNumber - 1); $pageMods = PAGE_MODS; $statement->bind_param('iii', $categoryData['id'], $firstNumber, $pageMods); $statement->execute(); $result = $statement->get_result(); if (!$result) { echo "An unexpected error occurred while fetching mods.
"; $statement->close(); } else { $modsPresent = false; while ($mod = $result->fetch_assoc()) { if (!$modsPresent) { echo '' . (isset($mod['description']) && $mod['description'] ? str_replace(["\r\n", "\n", "\r"], '
', htmlspecialchars(shortenDescription($mod['description']))) : "No description") . '
Publisher: ' . htmlspecialchars($mod['user']) . '' . (isset($_SESSION['user']) && $_SESSION['user'] == $mod['user_id'] ? ' | Edit mod' : '') . '
' . ($mod['rating'] ? '' . htmlspecialchars(number_format($mod['rating'], 2)) . ' ★' : '') . ' ' . ($mod['is_paid'] ? 'Paid' : 'Gratis') . 'No mods.
'; } $statement->close(); if ($totalPages > 1) { $begPage = $pageNumber - 2; $endPage = $pageNumber + 2; if ($endPage > $totalPages) { $begPage -= $endPage - $totalPages; $endPage = $totalPages; } if ($begPage < 1) { $endPage += 1 - $begPage; $begPage = 1; } echo '