I'm creating a calendar from scratch and can't figure out how to populate it with birthday events from a database. I'm not sure how to work the event data into the loop that creates the calendar days or even if that is the correct order I should be doing it?
$.post('fetch-event.php', function(result){
let days = "";
currentMonth = date.getMonth() +1;
// days of the current month and finds today's date
for(let i = 1; i<=lastDay; i++){
if(i === new Date().getDate() && date.getMonth() === new Date().getMonth()){
days += `<div class="today" id="${i}/${currentMonth}/${year}">${i}</div>`;
} else{
days += `<div id="${i}/${currentMonth}/${year}">${i}</div>`;
}
}
monthDays.innerHTML = days;
});
The 'result' of the post function produces the following.
[{"id":"1","name":"Elliot","date":"31/12/2020"},
{"id":"2","name":"Phil","date":"17/1/2020"},
{"id":"3","name":"Toby","date":"25/1/2021"}]
Ideally if the id date of the div matches the date from the database, I want to populate the div with the name of the person in the database rather than the day number but this is a bit beyond my technical know how.