每年将生日事件添加到jQuery完整日历中

我正在尝试插入jQuery完整的日历事件数据,在这种情况下代表用户的生日。 我正在从MySQL数据库中检索生日。 我们来看看脚本吧

php

 if ($birthday_r = $connection->query("SELECT CONCAT(name,' ',surname),MONTH(birthday),DAY(birthday) FROM users")){ while ($birthday_row = $birthday_r->fetch_row()){ $birthday_array[] = array( 'title' => $birthday_row[0], 'start' => Date("Y") . "-" . $birthday_row[1] . "-" . $birthday_row[2] ); } $json = json_encode($birthday_array); birthday_r->free(); } 

那么你如何看待将这个json编码信息存储到$json变量中

javascript

 jQuery("#calendar").fullCalendar({ // initialize full calendar header: { left: 'prev,next today', center: 'title', right: 'month,basicWeek,basicDay' },  viewDisplay: function(view){ var i = view.title.slice(-4); }, renderEvent: function(event){ } }); 

这在页面加载时效果很好,但我想在更改议程后(我的意思是例如按下一个或上一个按钮),每年的生日都会在日历中显示。 为此我建议使用viewDisplayrenderEvent函数,但我无法在php中修改year变量的方式以及javascript。 在viewDisplay函数变量中, i是year的数值(如2012)。 我的问题是以某种方式将带有i变量的Date("Y")更新为renderEvent函数。 此外,我试图将检索到的信息存储到javascript变量中,如此=>

在这个例子中考虑在php中给出

 'start' => $birthday_row[1] . "-" . $birthday_row[2] // php // below JavaScript code var json_obj =  var d = new Date(); for (var i=0;i<json_obj.length;i++){ json_obj[i] = d.getFullYear() + "-" + json_obj[i]; } // this scripts works as well but I can not manipulate after prev or next buttons are pressed on calendar 

PS。 我想伙计们,明白我想做什么,请帮我怎么做。 非常感谢事先:)

那么最简单的解决方案可能是改变你的PHP循环并为你的活动增加“多年”。

 while ($birthday_row = $birthday_r->fetch_row()){ $yearBegin = date("Y"); $yearEnd = $yearBegin + 10; // edit for your needs $years = range($yearBegin, $yearEnd, 1); foreach($years as $year){ $birthday_array[] = array( 'title' => $birthday_row[0], 'start' => $year . "-" . $birthday_row[1] . "-" . $birthday_row[2] ); } } 

两个缺点:

  • 你不能管理不同的生日(所以即使在他去世后,也可能发生一个人的出生日期)
  • 它会带来指数成本

您还可以通过重复事件来查看演示以构建前端解决方案。