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 may also take a look at the demo with repeating events to build a frontend solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.