From d81d4e4ca4a666ba9be48bc676b9b9f660aca896 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 24 May 2024 18:52:27 +0200 Subject: [PATCH] created api for getting all posts --- res/forum/api/get_posts.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 res/forum/api/get_posts.php diff --git a/res/forum/api/get_posts.php b/res/forum/api/get_posts.php new file mode 100644 index 0000000..036917b --- /dev/null +++ b/res/forum/api/get_posts.php @@ -0,0 +1,35 @@ + query("SELECT username FROM user WHERE BINARY username=\"" . $_SESSION["username"] . "\""); + +if ($out -> num_rows != 1) +{ + fail: + echo "nope"; + header("Location: ../../../index.php"); + return; +} + +$out = $database -> query("SELECT title, description, photo_id FROM post"); + +$output = array(); + +while (($res = $out -> fetch_assoc())) +{ + $buffer_array = array(); + + foreach ($res as $key => $value) + { + $buffer_array[$key] = $value; + } + + array_push($output, $buffer_array); +} + +header('Content-type: application/json'); +echo json_encode($output); \ No newline at end of file