简体   繁体   中英

fullcalendar.io render events with PHP/MySQL?

I'm trying to implement this calendar into my site using a "while" command with PHP. I dont know JSON or AJAX so not sure thats an option for me. i have this code right now but it renders a calendar FOR EACH EVENT and not 1 calendar with all events on it. I understand why, because i'm looping the whole calendar code, but is there a way to just loop the events?

<div class="widget">
    <div class="navbar">
        <div class="navbar-inner"><h6>Calendar</h6></div>
    </div>
    <div id="calendar" class="well"></div>
</div>

<?
    $query = "SELECT * FROM tevents";        
    $result = mysql_query($query) or die(mysql_error());
    // Print out result
    while($row = mysql_fetch_array($result)){
        $calname = $row['Event_Title'];
        $caldate = $row['Start_Date'];
        $calnotes = $row['Event_Details'];
        $caltime = $row['Event_Time'];
?>      

<script>
//===== Calendar =====//    
$('#calendar').fullCalendar({
    header: {
        left: 'prev,next',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    editable: false,
    events: [
        {
            title: '<?=$calname?>',
            start: '<?=$caldate?>'
        },
    ]
);
</script>

Create a json for events.

$events = [];
while($row = mysql_fetch_array($result)){
   $events[] = ['title' => $row['Event_Title'], 'start' => $row['Start_Date']];
}

And then, create the calendar with the $events

$('#calendar').fullCalendar({
                    header: {
                        left: 'prev,next',
                        center: 'title',
                        right: 'month,agendaWeek,agendaDay'
                    },
                    editable: false,
                    events: <?= json_encode($events) ?>
                });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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