從MySQL 資料庫建立JSON 數組
簡介
簡介url (可選)$year = date('Y');
$month = date('m');
$mysql_query = "SELECT * FROM events";
$result = mysql_query($mysql_query);
$json_array = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$event_id = $row['event_id'];
$title = $row['title'];
$start = "$year-$month-{$row['day']}";
if (!empty($row['end_day'])) {
$end = "$year-$month-{$row['end_day']}";
} else {
$end = null;
}
$url = $row['url'];
$event_array = array(
'id' => $event_id,
'title' => $title,
'start' => $start,
'end' => $end,
'url' => $url
);
array_push($json_array, $event_array);
}
echo json_encode($json_array);
end(可選)[
{
"id": 111,
"title": "Event1",
"start": "2023-03-10",
"url": "http://yahoo.com/"
},
{
"id": 222,
"title": "Event2",
"start": "2023-03-20",
"end": "2023-03-22",
"url": "http://yahoo.com/"
}
]
以上是如何從 MySQL 資料庫建立 JSON 數組以進行 Fullcalendar 整合?的詳細內容。更多資訊請關注PHP中文網其他相關文章!