user3092953 user3092953 - 6 months ago 29
Javascript Question

Add PHP to JS calender

I have bought a HTML/CSS template with a calendar application built in.

I am trying to show events from a MySQL database in the calendar. I have found the "Demo" appointments and not sure how to change these to my events in PHP.

Code snippet below:

var selectedEvent;
$('body').pagescalendar({
//Loading Dummy EVENTS for demo Purposes, you can feed the events attribute from
//Web Service
events: [{
title: 'Call Dave',
class: 'bg-success-lighter',
start: '2014-10-07T06:00:00',
end: '2014-10-07T08:00:24',
other: {}
}


From my DB I need to change title to
$event_name
, start to
$start_date
and end to
$end_date
... is this possible?

Answer

PHP as a server side language is executed before the content is delivered to the browser (before the html and javascript code is evaluated). Therefore you can easily include your php variables in any html/javascript like so:

events: [{
                title: '<?php echo $yourVariable; ?>',
                class: 'bg-success-lighter',
                start: '2014-10-07T06:00:00',
                end: '2014-10-07T08:00:24',
                other: {}
            }

$yourVariable could be assigned from a field in the database in your php code