Raghuveer
Raghuveer

Reputation: 797

Not able to feed full calendar with json events

I am trying the below code.. Integrating fullcalendar:-

<doctype! html>
    <html lang="urf-8">
    <head>
    <title>Full calendar</title>
    <link rel="stylesheet" href="fullcalendar.css"/>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css"/>
    <script type='text/javascript' src='jquery.js'></script>
    <script type='text/javascript' src='fullcalendar.js'></script>
    <script>
    $(document).ready(function() {
        $('#cal').fullCalendar({
            // put your options and callbacks here
            theme: true,
            header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,basicWeek,basicDay,agendaWeek,agendaDay'
                    },
            editable: false,
            events: "json-events.php",
    })
    });

    </script>
    </head>
    <body>
        <div id="cal" ></div>
    </body>
    </html>

Json-events.php code:-

<?php
    include("connect.php");
    $query = "select * from calendar";

    $res = mysql_query($query) or die(mysql_error());
    $events = array();
    while ($row = mysql_fetch_assoc($res)) {
        $eventsArray['id'] =  $row['calendar_id'];
        $eventsArray['title'] = $row['subject'];
        $eventsArray['start'] = mktime($row['start_date_time']);
        $events[] = $eventsArray;
    }
    echo json_encode($events);
    ?>

For debugging when i access json-events.php i am getting the result, but no events are displaying in fullcalendar.

Please help me..

Upvotes: 2

Views: 2374

Answers (1)

charlietfl
charlietfl

Reputation: 171690

Problem lies in format of your date strings in JSON. Format is not compatible with date formats for plugin. If you convert to UNIX timestamps using strtotime() in php they will work.

Upvotes: 4

Related Questions