我想显示来自 mysql 数据库的 json 事件。但我无法在日历中显示它。我认为事件中存在一些错误。但我不能指出。
这是我的代码:
日历.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);
?>
你能帮我解决这个问题吗??
谢谢。