javascriptjqueryarraysfullcalendar

jquery full calendar use loop to set events dynamically


i'm trying to use the jQuery full calendar and i must set events dynamically. these are examples of events:

events: [
                {
                    title: 'Long Event',
                    start: '2016-09-07',
                    end: '2016-09-10'
                },
                {
                    title: 'Conference',
                    start: '2016-09-11',
                    end: '2016-09-13'
                },
                {
                    title: 'Meeting',
                    start: '2016-09-12T10:30:00',
                    end: '2016-09-12T12:30:00'
                },
                {
                    title: 'Lunch',
                    start: '2016-09-12T12:00:00'
                },
                {
                    title: 'Meeting',
                    start: '2016-09-12T14:30:00'
                },
                {
                    title: 'Happy Hour',
                    start: '2016-09-12T17:30:00'
                },
                {
                    title: 'Click for Google',
                    url: 'http://google.com/',
                    start: '2016-09-28'
                }
            ]

I have arrays with titles, start dates and end dates of events and i must set them in a loop. Can someone help me and show me how must do? Thank's


Solution

  • In this way you can use loop to set events dynamically (In PHP):

    events:[
    <?php for ($i=0; $i <count($countOfArray); $i++) { ?> 
    {
         title: '<?php echo $countOfArray[$i]['Long_event']; ?>',
         start: '2016-09-07',
         end: '2016-09-10'
    },
    <?php } ?>
    ]
    

    You can also customize date as well:

    start: '<?php echo $countOfArray[$i]['YourDate']; ?>',