2021-04-12 19:38:30 +02:00
|
|
|
<?php
|
2021-04-12 20:06:21 +02:00
|
|
|
include "./lib/config.php";
|
|
|
|
include "./lib/mysql.php";
|
2021-04-12 19:38:30 +02:00
|
|
|
|
|
|
|
$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);
|