query("SELECT * FROM posts order by id desc limit $limit"); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $blogElement = [ "title" => $row["title"], "id" => $row["id"], "content" => $row["content"] ]; array_push($responseJSON, $blogElement); } } header('Content-Type: application/json'); echo json_encode($responseJSON);