Fullcalendar不会将mysql表中的数据输入日历

时间:2013-04-13 13:50:28

标签: php mysql json

我正在尝试使用Fullcalendar从mysql表中获取信息并在日历中输入信息。出现日历,但表中的信息都不在日历上。

这是我的代码。

calendar.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style type='text/css'>

    body {
            margin-top: 40px;
            text-align: center;
            font-size: 14px;
            font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
            }

    #loading {
            position: absolute;
            top: 5px;
            right: 5px;
            }

    #calendar {
            width: 900px;
            margin: 0 auto;
            }
</style>

<link rel='stylesheet' type='text/css' href='fullcalendar/fullcalendar.css' />
<script type='text/javascript' src='jquery/jquery.js'></script>
<script type='text/javascript' src='jquery/ui.core.js'></script>
<script type='text/javascript' src='jquery/ui.draggable.js'></script>
<script type='text/javascript' src='fullcalendar/fullcalendar.js'></script>

<script type='text/javascript'>
$(document).ready(function() {
    $('#calendar').fullCalendar({
        editable: true,
        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>

</head>

<body>
    <div id='loading' style='display:none'>loading...</div>
    <div id='calendar'></div>
    <p>json_events.php needs to be running in the same directory.</p>
</body>
</html>

json_events.php

<?php

    include("dbstuff.inc");

    $conn = mysql_connect($host, $user, $pass) or die(mysql_error());
    mysql_select_db($database, $conn) or die(mysql_error());

    $sql= "SELECT id, title, description, url, email, Stime, Etime, eventDate, DATE_FORMAT(eventDate, '%Y-%m-%dT%H:%i' ) AS startDate
        FROM events
        ORDER BY startDate DESC";
    $check = mysql_query($sql) or die(mysql_error());

    $events = array();
    while ($row = mysql_fetch_assoc($check)) {
        $eventArray['id'] = $row['id'];   
        $eventArray['title'] = $row['title'];
        $eventArray['description'] = $row['description'];
        $eventArray['url'] = $row['url'];
        $eventArray['email'] = $row['email'];
        $eventArray['startTime'] = $row['Stime'];
        $eventArray['EndTime'] = $row['Etime'];   
        $eventArray['title'] =  $row['Stime'] . " " . $row['title'];
        $eventArray['start'] = $row['startDate'];
        $eventsArray['allDay'] = "";
        $events[] = $eventArray;
}
echo json_encode($events);

?>

这是来自MySQL文件的数据

[
    {
        "id": "1",
        "title": "07:00:00 test1",
        "description": "werewr",
        "url": "http://www.nba.com",
        "email": "someone@host.com",
        "startTime": "07:00:00",
        "EndTime": "09:00:00",
        "start": "2013-04-22T00:00"
    },
    {
        "id": "2",
        "title": "11:00:00 test2",
        "description": "hello",
        "url": "http://www.nba.com",
        "email": "someone@host.com",
        "startTime": "11:00:00",
        "EndTime": "13:00:00",
        "start": "2013-04-15T00:00"
    }
]

1 个答案:

答案 0 :(得分:0)

你有事件:“json-events.php”和你的php文件是json_events.php