Fullcalendar无法呈现正确

时间:2015-01-28 09:26:47

标签: php jquery fullcalendar

我正在使用jQuery插件Fullcalendar到目前为止,我能够显示存储在MySQL数据库中的数据,但它没有以正确的方式显示。我的意思是:

例如:

}
    "id":"1","title":"Test",
    "start":"2015-01-28 10:30:00",
    "end":"2015-02-04 12:30:00",
    "url":"",
    "allDay":"false"
}

这是我的数据库中的一条记录。它应该显示在我的日历上

2015-01-28 10:30:002015-02-04 12:30:00

但事实并非如此。相反,allDaytrue(即使在数据库中它说false),我还需要添加其他日期。

例如:如果我想显示16-03到17-03的表格,我需要另外添加一天 - > 16-03至18-03(以便显示16-03至17-03)

这是我的SELECT查询:

<?php
$json = array();

// Query that retrieves events
$querySQL = "SELECT * FROM evenement";
// connection to the database
try {
    $bdd = new PDO("mysql:host=localhost;dbname=dbcontrol", "root", "");
} catch(Exception $e) {
    exit('Unable to connect to database.');
}
// Execute the query
$result = $bdd->query($querySQL) or die(print_r($bdd->errorInfo()));

// sending the encoded result to success page
    echo json_encode($result->fetchAll(PDO::FETCH_ASSOC));
?>

这是我的jQuery

$(document).ready(function() {
    var currentTime = new Date();
        /* initialize the external events
        -----------------------------------------------------------------*/

        $('#external-events .fc-event').each(function() {

            // store data so the calendar knows to render an event upon drop
            $(this).data('event', {
                title: $.trim($(this).text()), // use the element's text as the event title
                stick: true // maintain when user navigates (see docs on the renderEvent method)
            });

            // make the event draggable using jQuery UI
            $(this).draggable({
                zIndex: 999,
                revert: true,      // will cause the event to go back to its
                revertDuration: 0  //  original position after the drag
            });

        });


        /* initialize the calendar
        -----------------------------------------------------------------*/

        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            defaultDate: currentTime,
            editable: true,
            droppable: true,

            eventBackgroundColor: '#A80000',
            eventBorderColor: '#A80000',

            eventLimit: true, // allow "more" link when too many events
            events: {
                url: './php/select-events.php',
                error: function() {
                    $('#script-warning').show();
                }
            },
            loading: function(bool) {
                $('#loading').toggle(bool);
            }
        });

    });

如何以正确的方式显示记录。

编辑:

其他问题:

如何阻止echo json_encode($result->fetchAll(PDO::FETCH_ASSOC));在我的网页上显示整个json

屏幕截图:http://snag.gy/ZyKFa.jpg

1 个答案:

答案 0 :(得分:1)

echo json_encode($result->fetchAll(PDO::FETCH_ASSOC)); 

将始终在页面上输出您的json。如果你想隐藏它,你需要将它包装在somekind的容器中(例如javascript变量或div)。如果使用DOM容器,则隐藏容器。

像这样:

echo "<script> var myJSON = " . json_encode($result->fetchAll(PDO::FETCH_ASSOC)) . "</script>";

这将添加一个包含JSON的javascript变量

相关问题