website/public/API/getBlogElements.php

29 lines
No EOL
699 B
PHP

<?php
include "./lib/config.php";
include "./lib/mysql.php";
$position = $_GET['position'];
if($position == "index"){
$limit = $homeMaxPost;
} else if($position == "footer"){
$limit = $footerMaxPost;
} else {
die("wrong parameter");
}
$responseJSON = [];
$result = $conn->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);