我想從mysql數據庫中顯示json的事件。但我無法在日曆中顯示它。我認爲在事件中有一些錯誤。但我無法指出。在fullcalendar中顯示的事件
這裏是我的代碼:
calendar.php:
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
theme: true,
draggable: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
/*events: "json_events.php",*/
events: function(start, end, callback){
$.getJSON("json_events.php",
{
start: start.getTime(),
end: end.getTime()
},
function(result){
for(var i=0; i<result.length; i++){
var row = result[i];
}
//format the result into an array of calevents
$('#calendar').fullCalendar('addEvent', {id:row[0], title:row[1], start:row[2], end:row[3]});
//then pass the calevent array to the callback
callback(calevents);
}
);
},
eventClick: function(event){
editEventShow(event);
},
eventDrop: function(event, daydelta, minutedelta) {
alert(event.title + ' was moved ' + daydelta + ' days\n' + minutedelta + ' minutes\n'+
'(should probably update your database)');
},
dayClick: function(dayDate){
/*$('#dialog').dialog('open');
var date, month, year;
date = dayDate.getDate();
month = dayDate.getMonth()+1;
year = dayDate.getFullYear();
dayDate = year + "-" + month + "-" + date;*/
addEventShow(dayDate, this);
},
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
},
});
});
</script>
<style type='text/css'>
body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
json_events.php:
<?php
require("../../../connect/config.php");
$link = mysql_connect("$server","$user","$password") or die(mysql_error());
mysql_select_db($db);
$query = "SELECT id,title,start, end FROM events";
$result = mysql_query($query) or die(mysql_error());
$arr = array();
while($row = mysql_fetch_assoc($result)){
$arr[] = $row;
}
echo json_encode($arr);
?>
你能幫我這個問題?
謝謝。
您是否將開始和結束傳遞給getJSON函數,以便您可以在SQL查詢中放入WHERE子句?我沒有看到它被使用......這僅僅是爲了舉例的目的? – 2009-11-05 21:41:02