每年将生日事件添加到jQuery完整日历中 [英] add birthday events into jQuery full calendar each year

查看:47
本文介绍了每年将生日事件添加到jQuery完整日历中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



php



<$如果($ birthday_r = $ connection-> query(SELECT CONCAT(name,'',surname),MONTH(birthday),DAY(birthday)FROM users)){pre> b $ b 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 variable



javascript

  jQuery(#calendar)。fullCalendar({//初始化完整日历
标题:{
left:'prev,next today' ,
center:'title',
right:'month,basicWeek,basicDay'
},
<?php if(isset($ json_encode)){echoevents :。$ json。,;}?>
viewDisplay:function(view){
var i = view.title.slice(-4);
},
renderEvent:function(event){

}
});

Tthis在加载页面的时候效果很好,但我希望在更改日程之后(我的意思是按下一个或prev按钮),每年的生日都会在日历中显示。为此,我建议使用 viewDisplay renderEvent 函数,但是我无法修改year变量以及在JavaScript中。在 viewDisplay 函数变量 i 是年份的数值(如2012)。我的问题是以某种方式将 Date(Y) i 变量更新为 renderEvent 函数。此外,我试图将检索到的信息存储到JavaScript变量中,如下所示:



在本例中,认为在php中给出了

 'start'=> $ birthday_row [1]。  - 。 $ birthday_row [2] // php 

//以下JavaScript代码
var json_obj =<?php if(isset($ birthday_array)){echo $ birthday_array;}?>

var d = new Date();

for(var i = 0; i< json_obj.length; i ++){
json_obj [i] = d.getFullYear()+ - + json_obj [i];
} //此脚本也可以工作,但在日历上按下上一个或下一个按钮后,我无法操作

PS。我想大家,明白我想要做什么,请帮助我如何做到这一点。非常感谢!)解决方案最简单的解决方案可能是改变您的PHP循环并为您的多个年增加一个<$ p
$ b

  while($ birthday_row = $ birthday_r-> fetch_row()){
$ yearBegin = date( Y);
$ yearEnd = $ yearBegin + 10; //编辑您的需求
$年=范围($ yearBegin,$ yearEnd,1);

foreach($ year as $ year){
$ birthday_array [] = array(
'title'=> $ birthday_row [0],
'start '=> $ year。 - 。$ birthday_row [1]。 - 。$ birthday_row [2]
);
}
}

两个缺点:$ b​​
$ b


  • 您无法管理不同的生日(因此即使在他死后也可能发生某人的生日)
  • 它会导致指数成本



您也可以查看 demo ,重复构建前端解决方案。


I'm trying to insert into jQuery full calendar event data, which in this case represents birthdays of users. I'm retrieving birthdays from MySQL database. Let's take a look at script

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();
}

Then how you see storing this json encoded information into the $json variable

javascript:

jQuery("#calendar").fullCalendar({ // initialize full calendar
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
        <?php if (isset($json_encode)){echo "events: " . $json . ",";} ?>
        viewDisplay: function(view){
            var i = view.title.slice(-4);
        },
        renderEvent: function(event){

        }
    });

Tthis works nice when page is loaded, but I want that after changing agenda (I mean for example press next, or prev buttons) , for every year birthday be shown in calendar. For this purpose I've advised to use viewDisplay and renderEvent functions , but I can not modifying year variable how in php as well in javascript. in viewDisplay function variable i is numeric value of year (like 2012). My problem is to somehow update Date("Y") with i variable into renderEvent function . Also I've tried to store retrieved information into javascript variable like so =>

in this example considered that in php is given

'start' => $birthday_row[1] . "-" . $birthday_row[2] // php

// below JavaScript code
var json_obj = <?php if (isset($birthday_array)){echo $birthday_array;} ?>

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. I think guys , understand what I'm trying to do, pls help me how to do that . Thanks a lot beforehand :)

解决方案

Well the easiest solutions may be to alter your PHP loop and add "multiple" years to your events.

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]
        );
    }
}

Two drawbacks :

  • you can't manage different birthdays (so a person's birthdate may occur, even after his dead)
  • it leeds into exponential costs

You may also take a look at the demo with repeating events to build a frontend solution.

这篇关于每年将生日事件添加到jQuery完整日历中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆