首页 > 解决方案 > 来自 php 文件的完整日历的事件源

问题描述

我是 JS 新手,我正在尝试在日历中显示多个事件源。我查看了许多解决方案,但无法从两个文件中获取日历。它将使用 'events_source: 'event.php'' 从一个文件中获取资源。
这是加载文件的js:

var options = {     
    eventSources: [
        {
            url: 'event.php',
            type: 'POST',              
            color: 'yellow',   // a non-ajax option
            textColor: 'black' // a non-ajax option
        },
        {
            url: 'event2.php',
            type: 'POST',           
            color: 'green',   // a non-ajax option
            textColor: 'black' // a non-ajax option
        }
    ],  

这是 event.php(另一个文件类似并且都可以工作)。我不确定 json_encode (最后两行)是否有问题?

$sqlBookedEvents = "SELECT AppointmentLog_ID, `appointment`.`AppointmentTitle`, `appointment`.`Date_Appointment`, `appointment`.`StartTime`, `appointment`.`EndTime`, `appointment`.`EndTime`, `user`.`FirstName`, `user`.`Surname`, `yearGroup`.`Year` FROM appointment INNER JOIN user ON `appointment`.`PupilID_AppointmentLog` = `user`.`User_ID` INNER JOIN yearGroup ON `yearGroup`.`YearGroups_ID` = `user`.`YearGroupsID`
WHERE `appointment`.`StaffID_Appointment`= '$user' ";
$resultset = mysqli_query($conn, $sqlBookedEvents) or die("database error:". mysqli_error($conn));
$calendar = array();
while( $rows = mysqli_fetch_assoc($resultset) ) {   
    // convert  date to milliseconds

    $start = strtotime($rows['Date_Appointment']) * 1000;
    $end = strtotime($rows['Date_Appointment']) * 1000; 

    $calendar[] = array(        
        'id' =>$rows['AppointmentLog_ID'],
        $sTime =>$rows['StartTime'],
        $startTime =  date("h:i", $sTime),      
        $eTime = $rows['EndTime'],
        $endTime =  date("h:ia", $eTime),   
        $firstname = $rows['FirstName'],
        $surname = $rows['Surname'],
        $year = $rows['Year'],
        $dateappointment = $rows['Date_Appointment'],       
        $dateappointment2 = date( 'd/m', strtotime($dateappointment)),

        'title' => $dateappointment2. ' | ' .$startTime. ' - ' .$endTime. ' | ' .$firstname. ' ' .$surname. ' Yr ' .$year ,
        'url' => "#",
        "class" => 'event-important',
        'start' => "$start",
        'end' => "$end"
    );
}

$calendarData = array(
    "success" => 1, 
    "result"=>$calendar);
echo json_encode($calendarData);
exit;

标签: javascriptphpjsonfullcalendar

解决方案


推荐阅读