I am facing a problem while using the Weekly event calender Weekly event calender
In this demo there is static array passed for events the code for that is :
function getEventData() {
var year = new Date().getFullYear();
var month = new Date().getMonth();
var day = new Date().getDate();
return {
events : [
{
"id":1,
"start": new Date(year, month, day, 12),
"end": new Date(year, month, day, 13, 30),
"title":"Lunch with Mike"
},
{
"id":2,
"start": new Date(year, month, day, 14),
"end": new Date(year, month, day, 14, 45),
"title":"Dev Meeting"
},
{
"id":3,
"start": new Date(year, month, day + 1, 17),
"end": new Date(year, month, day + 1, 17, 45),
"title":"Hair cut"
},
{
"id":4,
"start": new Date(year, month, day - 1, 8),
"end": new Date(year, month, day - 1, 9, 30),
"title":"Team breakfast"
},
]
};
}
I want this data come from mysql using PHP. for this I write the php code
$query="Select id, start_time, end_time, title from calendar_events where status=1";
$result=mysql_query($query);
$count=mysql_num_rows($result);
$i=1;
while($row=mysql_fetch_array($result)) {
$myarray[] = array("id"=>$i,"start"=>$row['start_time'], "end"=>$row['end_time'], "title"=>$row['title']);
$i++;
}
I am getting the this array in Javascript as:
<script>
var myarr = <?php echo json_encode($myarray); ?>;
</script>
Now I want this data in the calendar. I tried many ways but couldn't get success. Please help in this.
If I understand your question, try this :
<script>
function getEventData() {
return json_encode('events'=>$myarray);
}
</script>
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.