Fullcalendar not display events from database

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?






Enable error handling with php.net/manual/en/function.error-reporting.php and php.net/manual/en/pdo.error-handling.php - If there are any php/pdo errors, update your question to contain them, if any.

– Funk Forty Niner
Sep 15 '18 at 14:12






It wasn't a php PDO related error. After reading some issue on github about fullcalendar I discovered that it will not load the data if the title key is omitted in the json passed from the php script. @FunkFortyNiner thanks for your help.

– user9741470
Sep 15 '18 at 14:58


PDO






You're welcome and glad to see you found the problem. I noticed that you posted an answer and wondering why you deleted it. Yes, I can see it. 10k+ members can see deleted answers. I feel you should undelete it and then accept it once it lets you. I'd be glad to upvote it.

– Funk Forty Niner
Sep 15 '18 at 15:09







@FunkFortyNiner because someone is trolling me by downvoting my questions lol.

– user9741470
Sep 15 '18 at 15:11






Believe me, I know what you mean.

– Funk Forty Niner
Sep 15 '18 at 15:11




1 Answer
1



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.


$_GET



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);

?>






Your answer is correct, but you say "for a strange reason the fullcalendar plugin will not load the data if the title key is omitted". The reason is not strange, it's clearly documented that the title field is required, and not optional.

– ADyson
Sep 17 '18 at 10:24






P.S. " 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."...why? fullCalendar provides these for a good reason, it's logical for your PHP script to make use of them. Anyway, the PHP code as shown in this answer will not work due to the missing parameter values in the SQL.

– ADyson
Sep 17 '18 at 10:25







@ADyson I'm using the code and It's working fine in my case also without the start/end parameters passed to the query, but your observation is correct about.

– user9741470
Sep 17 '18 at 11:56






" It's working fine in my case also without the start/end parameters passed to the query"....yes but in the code you've actually shown here, you're defining two parameters (with two ? characters) but then not supplying any values to the execute() statement. As far as I know, that will cause the query to fail.

– ADyson
Sep 17 '18 at 13:12


?






Ok I see. Thanks for the update. I still think you should use those values though. Once you have reservations going back many months or years it's going to be slow to load all of it, and you're going to be downloading lots of data which the user will not look at. fullCalendar gives you the start and end dates it actually needs data for in order to avoid this kind of problem.

– ADyson
Sep 17 '18 at 14:46



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế