From b1f345394e33899c47a275d0c866b36b265c7607 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Tue, 21 May 2024 20:02:52 +0200 Subject: [PATCH] sending list_users in json --- res/forum/admin.html | 8 +++++++- res/forum/api/list_users.php | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/res/forum/admin.html b/res/forum/admin.html index 13cb259..d07287f 100644 --- a/res/forum/admin.html +++ b/res/forum/admin.html @@ -20,7 +20,13 @@ url: "./res/forum/api/list_users.php", success: function(result) { - $("#left_panel").html(result); + let users = ""; + for (let i in result.users) + { + users += "
" + result.users[i] + "
"; + } + + $("#left_panel").html(users); } }); diff --git a/res/forum/api/list_users.php b/res/forum/api/list_users.php index d356855..a6ab2d5 100644 --- a/res/forum/api/list_users.php +++ b/res/forum/api/list_users.php @@ -18,7 +18,12 @@ if ($out -> num_rows != 1) $out = $database -> query("SELECT username FROM user ORDER BY id ASC"); +$output = array(); + while ($res = $out -> fetch_assoc()) { - echo "
" . $res["username"] . "
"; -} \ No newline at end of file + array_push($output, $res["username"]); +} + +header('Content-type: application/json'); +echo json_encode(["users" => $output]); \ No newline at end of file