user9741470
user9741470

Reputation:

Fullcalendar not display events from database

I'm working on a calendar to display some info about reservations. I've read the documentation about and I've implemented the calendar and the necessary scripts to fetch events information I need, but I've got a problem, I can't understand if the information is passed to the calendar from the PHP script.

It does not display any colored cell. Here is the code, can anyone help me with it?

PHP script

<?php

require_once 'Config.php';

$start = $_GET['start'];
$end =  $_GET['end'];

$events = array();

$stmt = $db->prepare('SELECT reservation_id, check_in, check_out FROM reservations WHERE check_in = ? AND check_out = ?');
  $stmt->execute(array($start, $end));
  $results = $stmt->fetchAll();
    foreach($results as $row){
      $events[] = array(
      'id'   => $row["reservation_id"],
      #'title'   => $row["title"],
      'start'   => $row["check_in"],
      'end'   => $row["check_out"]
      );
    }
echo json_encode($events);

?>

JS code

$(document).ready(function(){
  calendar();
});

var calendar = function(){
  $('#calendar').fullCalendar({
    events: {
        url: 'CalendarController.php',
        backgroundColor: 'red'
    }

  });
}

});

From the chrome inspector, I can see that the ajax call to obtain the information are passed and no error is logged. Maybe I made an error in the PHP script?

Upvotes: 1

Views: 423

Answers (1)

user9741470
user9741470

Reputation:

As I write in a reply to a comment, I discovered that for a strange reason the fullcalendar plugin will not load the data if the title key is omitted in the json response from the php script. I've also modified my php code to serve a response without use the $_GET parameters passed from the fullcalendar when data are loaded using ajax.

here is the code, I hope it can be useful for someone else that has the same problem.

<?php

require_once 'Config.php';

$events = array();

$stmt = $db->prepare('SELECT reservation_id, check_in, check_out FROM reservations');
  $stmt->execute();
  $results = $stmt->fetchAll();
    foreach($results as $row){
      $events[] = array(
      'id'   => $row["reservation_id"],
      'title'   => 'ND',
      'start'   => $row["check_in"],
      'end'   => $row["check_out"]
      );
    }
echo json_encode($events);

?>

Upvotes: 1

Related Questions