php - add birthday events into jQuery full calendar each year


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


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

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


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 useviewDisplay andrenderEvent functions , but I can not modifying year variable how in php as well in javascript. inviewDisplay function variablei is numeric value of year (like 2012). My problem is to somehow updateDate("Y") withi variable intorenderEvent 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.

People are also looking for solutions to the problem: php - Precedence of AND and OR into an IF statement


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.