From 6e27fb9de11843b7bb605fe85cb628b6e4882787 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 30 Apr 2025 00:17:39 +0500 Subject: feat: PAGination! --- public/emotesets.php | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'public/emotesets.php') diff --git a/public/emotesets.php b/public/emotesets.php index ebec077..fdf32d5 100644 --- a/public/emotesets.php +++ b/public/emotesets.php @@ -13,6 +13,10 @@ $db = new PDO(DB_URL, DB_USER, DB_PASS); $emote_sets = null; $emote_set = null; +$page = max(1, intval($_GET["p"] ?? "0")); +$total_emotesets = 1; +$total_pages = 1; + if ($id == "global") { $stmt = $db->prepare("SELECT * FROM emote_sets WHERE is_global = true"); $stmt->execute(); @@ -36,9 +40,8 @@ if ($id == "global") { } } } else if (intval($id) <= 0 && intval($alias_id) <= 0) { - $page = intval($_GET["p"] ?? "0"); $limit = 20; - $offset = $page * $limit; + $offset = ($page - 1) * $limit; $stmt = $db->prepare("SELECT * FROM emote_sets LIMIT ? OFFSET ?"); $stmt->bindParam(1, $limit, PDO::PARAM_INT); @@ -63,6 +66,10 @@ if ($id == "global") { } } } + $count_stmt = $db->prepare("SELECT COUNT(*) FROM emote_sets"); + $count_stmt->execute(); + $total_emotesets = intval($count_stmt->fetch()[0]); + $total_pages = ceil($total_emotesets / $limit); } else if (intval($alias_id) > 0) { $alias_id = intval($alias_id); $stmt = $db->prepare("SELECT es.* FROM emote_sets es @@ -153,18 +160,16 @@ if (CLIENT_REQUIRES_JSON) {
-
'; + + if ($total_pages > 1) { + echo '' ?> +
+ + '; @@ -195,10 +211,9 @@ if (CLIENT_REQUIRES_JSON) { } } ?> -
+ - -- cgit v1.2.3