I have a huge database and a lot of events. Every time I go to the Calendar Mainpage (monthly view) all the existing events in the database are loaded, despite I'm only viewing the current month. At the moment my html page is over 3MB big and tends to slow down my browser tab.
To solve this problem I started to change the code to fetch only the events from the current month as json. Unfortunately, the start and end dates for the date-range are not working - the page is still fetching all events from the database. I have already done a few hours of research and a lot of tweaks.
So far I managed to fetch my FullCalendar.io events - I have two event sources - so I used:
eventSources: [
{
url: 'include/load-calendar-event.php', // use the `url` property
color: '#008000',
},
{
url: 'include/load-calendar-event-retour.php', // use the `url` property
color: '#008000',
},
// any other sources...
],
The corresponding two files to fetch the events are almost identical - so one should be enough:
load-calendar-event.php
require_once('bdd.php');
$sql = "SELECT * FROM messages"; // this selects all rows
$req = $bdd->prepare($sql);
$req->execute();
$events = $req->fetchAll();
$data = array();
foreach($events as $event) {
$start = explode(" ", $event['start']);
$end = explode(" ", $event['end']);
if($start[1] == '00:00:00'){
$start = $start[0];
}else{
$start = $event['start'];
}
if($end[1] == '00:00:00'){
$end = $end[0];
}else{
$end = $event['end'];
}
$data[] = array(
'id'=> $event['id'],
'title'=> $event['title'],
'start'=> $start,
'end'=> $end,
'color'=> $event['color']
);
}
echo json_encode($data);
By calling the Calendar Page the browsers makes the following calls - please note the date (2020-01-01 - 2020-02-01) and data format:
...include/load-calendar-event.php?start=2020-01-01&end=2020-02-01&_=1578601056565
and
...include/load-calendar-event-retour.php?start=2020-01-01&end=2020-02-01&_=1578601056566
The date format of the events are saved in the database with the following format (YYYY-MM-DD HH:mm:ss):
2020-01-11 10:00:00
Question:
Any idea how to fetch the events ONLY for the current month?