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

Php 每年将生日事件添加到jQuery完整日历中,php,javascript,jquery,mysql,fullcalendar,Php,Javascript,Jquery,Mysql,Fullcalendar,我试图在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()){

我试图在
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'
        },
        <?php if (isset($json_encode)){echo "events: " . $json . ",";} ?>
        viewDisplay: function(view){
            var i = view.title.slice(-4);
        },
        renderEvent: function(event){

        }
    });

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

最简单的解决方案可能是改变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]
        );
    }
}
两个缺点:

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

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

也许我遗漏了什么。您希望这些活动如何显示在日历上?它与有开始日期的常规活动不同吗?你能再解释一下吗?
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]
        );
    }
}