0

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?

Bogdan Kuštan
  • 5,427
  • 1
  • 21
  • 30
Shane
  • 753
  • 3
  • 8
  • 21
  • please read that before: http://stackoverflow.com/help/how-to-ask and then http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming – Regis Portalez May 09 '16 at 13:18
  • @RegisPortalez - Thanks for the links, however it doesn't seem to help my answer unless you can provide an answer/explanation along with it? – Shane May 09 '16 at 13:19
  • Question is unclear. Is it about js, php or sql? And it looks like you're trying to modify server variables from a db in the middle of some JavaScript, what makes no sense – Regis Portalez May 09 '16 at 13:22
  • 2
    @user3092953 , it seems you didn't get Regis 's answer , he refered you to read the stackoverflow community's rules and regulations , about how to post question and what to add in your question. – Arsh Singh May 09 '16 at 13:22
  • 1
    You could do an API call and fetch the events from your database and encode it to JSON. – Matheno May 09 '16 at 13:24
  • @RegisPortalez - It's still got 2 upvotes though? So can't be that unclear can it? – Shane May 09 '16 at 13:31
  • it's javascript tag... – Regis Portalez May 09 '16 at 13:32
  • Sorry I'm missing the point here @RegisPortalez... – Shane May 09 '16 at 13:33

2 Answers2

2

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

Velimir Tchatchevsky
  • 2,812
  • 1
  • 16
  • 21
1

Try this:

var selectedEvent;
$('body').pagescalendar({
    //Loading Dummy EVENTS for demo Purposes, you can feed the events attribute from 
    //Web Service
    events: [{
        title: '<?php echo $event_name; ?>',
        class: 'bg-success-lighter',
        start: '<?php echo $start_date; ?>',
        end: '<?php echo $end_date; ?>',
        other: {}
    }
});
prava
  • 3,916
  • 2
  • 24
  • 35
  • What? No... he cant echo php variables inside a .js file. And even if he tweaked his server to run that, it would be bad practice – Ole Haugset May 10 '16 at 11:56