dragam0217 2012-09-06 18:37
浏览 154
已采纳

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

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 :)

  • 写回答

1条回答 默认 最新

  • douying7289 2012-09-07 07:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿