4 Replies - 4843 Views - Last Post: 03 January 2013 - 09:50 AM Rate Topic: -----

#1 makamo66  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 43
  • Joined: 04-February 09

Mixing jquery with PHP

Posted 03 January 2013 - 06:44 AM

I have a jquery calendar in my cakephp application with

<?php //foreach ($mealplans as $mealplan){ ?>
				{ 
					title: '<?php echo $mealplan['Mealplan']['event_name'] . ", ". $mealplan['Mealplan']['total_calories']. " cals"; ?>',
					start: new Date(y, m, <?php
					$event = $mealplan['Mealplan']['event_date']; echo substr($event, 0, -8); ?>, 0),
					end: new Date(y, m, 16),
					allDay: true,
					url: 'http://localhost/mealplans/view/1'
				},
				<?php //} ?>



When I uncomment foreach and its curly bracket at the end then it prints out the first of my meal plans on January 15 until January 16 but I want it to print out all of them. Most of the php is working in the jquery code it's just this one part that doesn't work. When I uncomment the foreach and its end bracket then the calendar disappears. You can see it at http://myownmealplan...endars/navigate The calendar code is from http://arshaw.com/fu...dar/docs/usage/

Is This A Good Question/Topic? 0
  • +

Replies To: Mixing jquery with PHP

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,444
  • Joined: 08-June 10

Re: Mixing jquery with PHP

Posted 03 January 2013 - 06:50 AM

see line #6, there you define the end to always be the 16th.

and the fact that you constantly switch between JS and PHP doesn’t make it any clearer. I highly recommend to make a template for the JS code and then feed the values into that.
Was This Post Helpful? 0
  • +
  • -

#3 makamo66  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 43
  • Joined: 04-February 09

Re: Mixing jquery with PHP

Posted 03 January 2013 - 09:09 AM

Thanks for your input but I don't know what it means to make a JS template.
Was This Post Helpful? 0
  • +
  • -

#4 makamo66  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 43
  • Joined: 04-February 09

Re: Mixing jquery with PHP

Posted 03 January 2013 - 09:16 AM

I found the problem. Some of the meal plans didn't have dates associated with them and thus the date code was corrupted. It works now at localhost.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,444
  • Joined: 08-June 10

Re: Mixing jquery with PHP

Posted 03 January 2013 - 09:50 AM

View Postmakamo66, on 03 January 2013 - 05:09 PM, said:

I don't know what it means to make a JS template.

you make a PHP template (of text that is later parsed as JS), not a template in JS.

very, very simple example:
$ex = <<<JS
<script type="application/javascript">
function doSomething()
{
    alert("%s");
}
</script>
JS;
// later
printf($ex, "baby");

This post has been edited by Dormilich: 03 January 2013 - 09:50 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1