Javascript FullCalendar:使用比较日期更改事件颜色

Javascript FullCalendar:使用比较日期更改事件颜色,javascript,php,html,fullcalendar,Javascript,Php,Html,Fullcalendar,最近,我开始把arshaw的日程安排得满满的。在开发过程中,我在网站上搜索解决方案,以根据活动日期和当前日期更改活动颜色。这段代码是用HTML和PHP以及Javascript编写的 这是对我自己的问题的回答,基于我所取得的成绩,因为没有类似的问题可以解决这个问题 下面是我的答案和完整日历的样子 为了澄清,我使用odbc和microsoft Access作为数据库 我的做法如下: 完整日历脚本中的事件 events: [ <?php includ

最近,我开始把arshaw的日程安排得满满的。在开发过程中,我在网站上搜索解决方案,以根据活动日期和当前日期更改活动颜色。这段代码是用HTML和PHP以及Javascript编写的

这是对我自己的问题的回答,基于我所取得的成绩,因为没有类似的问题可以解决这个问题

下面是我的答案和完整日历的样子


为了澄清,我使用odbc和microsoft Access作为数据库

我的做法如下:

完整日历脚本中的事件

  events: [
        <?php 
            include 'connect.php'; //connect to database

      function getColor($date) {
        $currentDate = date('Y-m-d');
        $oneweekDate = date('Y-m-d',strtotime('-1 week')); // this part is to compare with the date 1 week ago
        $eventColor = '';
        if ($date == $currentDate) {
            $eventColor = '#fb8c00';
        } else if($date > $oneweekDate && $date < $currentDate){
            $eventColor = '#ff0000';
        } else if($date < $oneweekDate){
            $eventColor = '#696969';
        } else {
            $eventColor = '#008000';
        }
        return $eventColor;
    }

    $sql="SELECT * FROM masterlist1";
    $result=odbc_exec($conn,$sql);
        while($row=odbc_fetch_array($result)){
            $newEnd = date("Y-m-d", strtotime($row['Calibration_Due_Date']));
            $color = getColor($newEnd); //store the date from database into a PHP variable and then call the PHP function getColor to get return result
        ?>
       {  
        title: '--title--',  <!--u may get info from fullcalendar.io on the documentations for these parts-->
        start: '--start date--', 
        end: '--end date--', 
        description : '--description--',
        color : '<?php echo $color?>' <!-- this part is where we get the return result from the getColor function and store it into $color variable and then echo it out here for the event color.-->
      }, 
      <?php } ?>
      ],
事件:[
{  
标题:'--标题--',
开始:'--开始日期--',
结束:'--结束日期--',
说明:'--说明--',
颜色:“”
}, 
],