From 6e27fb9de11843b7bb605fe85cb628b6e4882787 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 30 Apr 2025 00:17:39 +0500 Subject: feat: PAGination! --- public/users.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'public/users.php') diff --git a/public/users.php b/public/users.php index 123d37f..914f890 100644 --- a/public/users.php +++ b/public/users.php @@ -16,9 +16,9 @@ $alias_id = $_GET["alias_id"] ?? ""; $db = new PDO(DB_URL, DB_USER, DB_PASS); if ($id == "" && $alias_id == "") { - $page = $_GET["p"] ?? "0"; - $limit = 50; - $offset = $page * $limit; + $page = max(1, intval($_GET["p"] ?? "1")); + $limit = 25; + $offset = ($page - 1) * $limit; $search = "%" . ($_GET["q"] ?? "") . "%"; $stmt = $db->prepare("SELECT id, username, joined_at, last_active_at FROM users @@ -29,7 +29,11 @@ if ($id == "" && $alias_id == "") { $stmt->bindParam(3, $offset, PDO::PARAM_INT); $stmt->execute(); - $all_user_count = $search ? $stmt->rowCount() : $db->query("SELECT COUNT(*) FROM users")->fetch()[0]; + $count_stmt = $db->prepare("SELECT COUNT(*) FROM users WHERE username LIKE ?"); + $count_stmt->execute([$search]); + + $total_users = $count_stmt->fetch()[0]; + $total_pages = ceil($total_users / $limit); if ($is_json) { header("Content-Type: application/json"); @@ -63,11 +67,11 @@ if ($id == "" && $alias_id == "") {
rowCount() != 0) { + if ($total_users != 0) { echo ''; echo ''; echo ''; @@ -94,8 +98,18 @@ if ($id == "" && $alias_id == "") { ?> + 1) { + echo '' ?> + +
+ +
+ - -- cgit v1.2.3
UsernameLast active