Reputation: 3435
I am new to ajax/jquery in gerneral and found jquery's fullcalendar made by Adam Shaw. This looks like exactly what i need.
I found a few tutorials on how to get it to read from a php/mysql setup which works fine if I use exactly the same field names they are telling me (start, end, etc). What I am wondering is how do I tell it to use my own date fields as start and end dates. I also want to add some extra fields like comments (i already have a calendar database with data in it that I want to use without restructuring it as other things use the same database).
Field name examples:
If someone could let me know how to tell it to use the custom date fields as well as displaying other custom fields that would be awesome.
The current script I have is: The jquery/ajax currently using
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate(),
m = date.getMonth(),
y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
buttonText: {
today: 'Today',
month: 'Month',
week: 'Week',
day: 'Day'
},
events: "../calendar/internal/events.php"
});
});
</script>
events.php
<?php
$json = array();
$requete = "SELECT * FROM internal_calendar ORDER BY id";
try {
$bdd = new PDO('mysql:host=localhost;dbname=calendarDB', 'root', 'securepassword');
} catch(Exception $e) {
exit('Unable to connect to database.');
}
$resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));
echo json_encode($resultat->fetchAll(PDO::FETCH_ASSOC));
Any help would be appreciated.
Thanks, jAC
Upvotes: 0
Views: 1739
Reputation: 1465
Before making json format of your result, you need to do some stuff to make acceptable for fullcalendar as event.
$result = $resultat->fetchAll(PDO::FETCH_ASSOC);
$events = array();
foreach ($result as $row) {
$events[] = array (
'start' => date('Y-m-d H:i:s', strtotime($row['startDate'])),
'end' => date('Y-m-d H:i:s', strtotime($row['endDate'])),
'comments' => $row['comments'],
'reoccuring' => $row['reoccuring'],
'title' => 'Set title here', // Set comment here to show in event block.
)
}
echo json_encode($events);
event's title property is used to show data in event block in fullcalendar. You can set comments as title.
'title' => $row['comments']
That's it.
Upvotes: 2