Cat-api-open/includes/announcements.php
2025-07-12 13:33:32 +08:00

25 lines
646 B
PHP

<?php
$sql = "SELECT `date`, `content` FROM announcement ORDER BY `date` DESC"; // 按日期降序排列
$stmt = $pdo->prepare($sql);
$stmt->execute();
// 获取查询结果
$announcements = $stmt->fetchAll(PDO::FETCH_ASSOC);
// 处理日期格式
foreach ($announcements as &$announcement) {
$announcement['date'] = date('Y-m-d', strtotime($announcement['date']));
}
// 准备返回的数据
$response = [
"code" => 200,
"announcements" => $announcements,
"message" => "Success"
];
// 将数组转换为 JSON 格式
$json_response = json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
echo $json_response;
?>