29 lines
687 B
PHP
29 lines
687 B
PHP
|
<?php
|
||
|
include "config.php";
|
||
|
include "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);
|