简体   繁体   English

Fullcalendar 不显示数据库中的事件

[英]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.我已经阅读了有关的文档并且我已经实现了日历和必要的脚本来获取我需要的事件信息,但是我遇到了一个问题,我无法理解信息是否从 PHP 脚本传递到日历.

It does not display any colored cell.它不显示任何彩色单元格。 Here is the code, can anyone help me with it?这是代码,有人可以帮我吗?

PHP script PHP脚本

<?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 JS代码

$(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.从 chrome Inspector 可以看到获取信息的 ajax 调用通过了,没有记录错误。 Maybe I made an error in the PHP script?也许我在 PHP 脚本中犯了错误?

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.当我在对评论的回复中写道时,我发现由于一个奇怪的原因,如果在 php 脚本的 json 响应中省略了标题键,fullcalendar 插件将不会加载数据。 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.我还修改了我的 php 代码,以便在使用 ajax 加载数据时不使用从 fullcalendar 传递的$_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);

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM