cartmander
cartmander

Reputation: 182

How to dynamically add events on fullCalendar using data retrieved from database(phpmyadmin)?

I am grateful in advance of any help I receive on this. I also apologise if my error is obvious. My problem is I can't seem to find an idea on how to display all the elements of my array to populate my events. As you can see, I did this statically. I wish to find a way on how to populate events dynamically using for loop.

$(document).ready(function() {
    generateEvents();
});

function generateEvents()
{
        // these are the data that i retrieved from database (phpmyadmin)
        var primaryAssets = <?php echo json_encode($primaryAsset_Array); ?>;
        var releaseDates = <?php echo json_encode($releaseDate_Array); ?>;


        var events = [];
        for(var i = 0;i < count;i++)
        {       
            $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
          //defaultDate: '2014-06-12',
            editable: true,
            weekMode: 'liquid',
            weekends: true,

            events: [
                {
                    title: primaryAssets[0],
                    start:  releaseDates[0]
                },
                {
                    title: primaryAssets[1], 
                    start:  releaseDates[1]
                // i wish to do this dynamically...
                },

            ],

            loading: function(bool) {
                $('#loading').toggle(bool);
            }

        });
    }
}

Upvotes: 0

Views: 1996

Answers (2)

user3129207
user3129207

Reputation: 61

If You are not comfortable using "eventSources", try this:

  1. Go through the demos given in full calendar.

  2. Use 'json.html' example.

  3. Modify the "events.json" file by using php before the calendar script is called.

Upvotes: 0

Ballantine
Ballantine

Reputation: 338

In your fullCalendar function options, you can add :

eventSources: {
    url : 'YOUR_PHP_URL'
}

It will create an ajax request to YOUR_PHP_URL. Then, in your Php script, you have to send data in json format.

You have an example in http://arshaw.com/fullcalendar/docs/google_calendar/

Upvotes: 2

Related Questions