diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-22 03:48:11 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-22 03:48:11 +0500 |
| commit | bb05b244f95bb6f507c9e825efd4da4d3d93662b (patch) | |
| tree | e29d191acaa319ff7850966e882611fa8148a140 /public/users.php | |
| parent | df783376d2b3bdd8fe5e0e558fa781f40babd7f3 (diff) | |
feat: search functionality
Diffstat (limited to 'public/users.php')
| -rw-r--r-- | public/users.php | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/public/users.php b/public/users.php index 73f1d54..fae1e70 100644 --- a/public/users.php +++ b/public/users.php @@ -17,12 +17,23 @@ if ($id == "") { $page = $_GET["p"] ?? "0"; $limit = 50; $offset = $page * $limit; - $stmt = $db->prepare("SELECT id, username, joined_at, last_active_at FROM users ORDER BY last_active_at DESC LIMIT ? OFFSET ?"); - $stmt->bindParam(1, $limit, PDO::PARAM_INT); - $stmt->bindParam(2, $offset, PDO::PARAM_INT); + $search = $_GET["q"] ?? ""; + $stmt = $db->prepare("SELECT id, username, joined_at, last_active_at + FROM users + " . ($search != "" ? " WHERE username LIKE ? " : "") . " + ORDER BY last_active_at DESC LIMIT ? OFFSET ?"); + if ($search == "") { + $stmt->bindParam(1, $limit, PDO::PARAM_INT); + $stmt->bindParam(2, $offset, PDO::PARAM_INT); + } else { + $search = "%$search%"; + $stmt->bindParam(1, $search, PDO::PARAM_STR); + $stmt->bindParam(2, $limit, PDO::PARAM_INT); + $stmt->bindParam(3, $offset, PDO::PARAM_INT); + } $stmt->execute(); - $all_user_count = $db->query("SELECT COUNT(*) FROM users")->fetch()[0]; + $all_user_count = $search ? $stmt->rowCount() : $db->query("SELECT COUNT(*) FROM users")->fetch()[0]; if ($is_json) { header("Content-Type: application/json"); |
