使用FullCalendar(http://arshaw.com/fullcalendar/)通過JSON拉從一個MySQL數據庫表的事件。事件正在日曆中顯示,但由於某些原因,它忽略了事件的時間(小時,分鐘,秒)。這裏是javascript中的日曆頁 -
<script type='text/javascript'>
$(document).ready(function() {
$('#calendar').fullCalendar({
editable: false,
events: "json-events.php",
eventDrop: function(event, delta) {
alert(event.title + ' was moved ' + delta + ' days\n' +
'(should probably update your database)');
},
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
}
});
});
</script>
和我的JSON PHP文件(注意,我包括時間日期後,目前該字段設置爲僅日期):
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/includes/pdo_conn.inc.php';
$getEventsSQL = $db->query("SELECT id, title, date_start AS start, date_end AS end FROM training");
$events = array();
while ($row = $getEventsSQL->fetch()) {
$start = $row['start'];
$end = $row['end'];
$title = $row['title'];
$eventsArray['id'] = $row['id'];
$eventsArray['title'] = $title;
$eventsArray['start'] = $start . " 13:00:00";
$eventsArray['end'] = $end . " 14:00:00";
$eventsArray['url'] = "http://somewhere.org";
$events[] = $eventsArray;
}
echo json_encode($events);
?>
以上輸出:
[{"id":"13","title":"Test 1","start":"2010-05-18 13:00:00","end":"0000-00-00 14:00:00","url":"http:\/\/tapp-essexvfd.org"},{"id":"14","title":"Test 2","start":"2010-06-18 13:00:00","end":"2010-06-19 14:00:00","url":"http:\/\/tapp-essexvfd.org"},{"id":"15","title":"Test 3","start":"2010-06-18 13:00:00","end":"0000-00-00 14:00:00","url":"http:\/\/somewhere.org"},{"id":"16","title":"test4","start":"2010-05-03 13:00:00","end":"0000-00-00 14:00:00","url":"http:\/\/somewhere.org"}]
謝謝!
編輯
下面是修改PHP以反映接受的解決方案。謝謝!
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/includes/pdo_conn.inc.php';
$getEventsSQL = $db->query("SELECT id, title, date_start AS start, time FROM events WHERE date_start >= NOW() AND status = 1");
$events = array();
while ($row = $getEventsSQL->fetch()) {
$start = $row['start'];
$title = $row['title'];
$eventsArray['id'] = $row['id'];
$eventsArray['title'] = $title;
$eventsArray['start'] = $start . " " . $row['time'];
$eventsArray['end'] = $end;
$eventsArray['url'] = "#";
$eventsArray['allDay'] = false;
$events[] = $eventsArray;
}
echo json_encode($events);
?>
感謝分享它幫助我感謝 – Devjosh 2011-10-20 13:49:45
夜晚的問題,是否有可能給我一個你的數據庫的快照,看看我應該如何根據你的代碼來設計它。 – 2012-04-17 02:59:48