Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery calendar pull information from mysql database

I have a jquery calendar and I want to populate this with data from mysql database, my php script works on its own i.e displays data correctly however I am struggling to get this to work with the calendar script. Any ideas anyone?

Here's my code;-

<script>


$(document).ready(function() {

    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
        defaultDate: '<?php echo date("Y/m/d");?>',
        editable: true,
        eventLimit: true, // allow "more" link when too many events
        events: [
            {
                id: 999,
                title: 'Repeating Event',
                start: '2014-11-16T16:00:00'
            },

            {
                title: 'name',
                start: '2015-04-27',
                end:   '2015-04-29',
            },

            {
                title: 'Michael',
                start: '2015-04-27',
                end:   '2015-04-27',
            },
            {
                title: 'Matthew',
                start: '2015-04-27',
                end:   '2015-05-01',
            },
            {
                title: 'Eric',
                start: '2015-05-04',
                end:   '2015-05-08',
            }
        ]
    });

});

php include('../include/connect.php');

$result = mysql_query("SELECT * FROM holidays ORDER BY id DESC");
or die(mysql_error()); 

 while($row = mysql_fetch_array($result))
 {

echo "  {   title:'" . $row['title'] . "',";
echo "      start:'" . $row['start'] . "',";
echo "      end:'" . $row['end'] . "'},";
 }
like image 556
Dan Avatar asked May 11 '26 00:05

Dan


1 Answers

You are missing events as json feed. click for docs

JS:

$('#calendar').fullCalendar({
    events: '/myfeed.php'//place url to your php script here.
});

PHP:

php include('../include/connect.php');
$result = mysql_query("SELECT * FROM holidays ORDER BY id DESC") or die(mysql_error()); 
$events = array();
while($row = mysql_fetch_array($result))
 {
    $events[] = array(
                    "title" => $row['title'],
                    "start" => $row['start'],
                    "end" => $row['end']
                );
 }
echo json_encode($events);
like image 111
valar morghulis Avatar answered May 12 '26 13:05

valar morghulis