0

So I am trying to use this plugin: http://w3widgets.com/responsive-calendar/

And the way the calendar is initialized and have events added is like so:

<script>
   <?php $today = date('Y-m'); ?>
   $( document ).ready( function() {
    $(".responsive-calendar").responsiveCalendar({
      time: '<?php echo $today; ?>',
      events: {
       "2014-04-30": {"number": 1, "badgeClass": "badge-warning", "url": "http://w3widgets.com/responsive-calendar"},
       "2013-04-26": {"number": 1, "badgeClass": "badge-warning", "url": "http://w3widgets.com"}, 
       "2013-05-03": {"number": 1, "badgeClass": "badge-error"}, 
       "2013-06-12": {}}
     });
    });
</script>

I want to generate the events with a foreach because the events are all stored in a database. I tried to do the following:

events: { <?php foreach($events as $event): ?> "<?php echo $event->date; ?>"...

But I get an error that says the ) in the ($events as $event) is unexpected.

How can I do this, I must be able to or the calendar has to disappear. Plain and simple.

UPDATE

If I var_dump() the $events I get the following string (shortened to the first event!)

array(3) { [0]=> object(stdClass)#21 (5) { ["id"]=> string(1) "1" ["name"]=> string(17) "State Large Group" ["school"]=> string(9) "NHS Bands" ["date"]=> string(9) "4-16-2014" ["showHome"]=> string(1) "1" }...

And If I events: <?php echo json_encode($events); ?> it doesn't encode in the correct order. It does:

events: [{"id":"1","name":"State Large Group","school":"NHS Bands","date":"4-16-2014","showHome":"1"},{"id":"2","name":"State Solo\/Ensemble","school":"NHS Bands","date":"4-26-2014","showHome":"1"},{"id":"3","name":"League Music Festival","school":"RVMS Bands","date":"4-29-2014","showHome":"1"}]  });

When it needs to be something like:

"2013-06-12": {}
3
  • 1
    Have you tried it with brackets? <?php foreach($events as $event){ ?> "<?php echo $event->date; ?>"<?php } ?> Commented Apr 17, 2014 at 23:13
  • 1
    Maybe provide us with the actual code portion? Commented Apr 17, 2014 at 23:15
  • We can help you further if you show us where $events gets its contents. Commented Apr 17, 2014 at 23:20

2 Answers 2

1
events: <?php echo json_encode($events) ?>
Sign up to request clarification or add additional context in comments.

Comments

0

You can convert your database result to json and pass it to events.

JSON encode MySQL results

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.