Full Calendar Event Data
I'm thinking of using FullCalendar as an event 开发者_JAVA百科calendar on a website.
My question: Is there any documentation or examples of using PHP/MySQL to store an access event data?
Thanks!
I'm doing this too, and I had wished that there was a more complete example of the PHP/MySQL side, since I'm usually an ASP.NET/MS-SQL guy, so I had to spend more time than I would have liked on some basic stuff. Here's an outline of what I did. It's pretty basic.
First, I created a table in MySQL that looks like this:
CREATE TABLE `events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(200) NOT NULL,
`start_date` datetime NOT NULL,
`end_date` datetime NOT NULL,
`event_url` varchar(200) DEFAULT NULL,
`all_day` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Then, I wrote a PHP program named json-events.php, which I used as the event source for the calendar. In this program, you first need to get the start and end dates for the currently-displayed calendar:
$start_date = $_GET['start'];
$end_date = $_GET['end'];
Then, you need to run a SQL query to get events in that window:
$sqlcommand = "select * from events
where start_date between from_unixtime($start_date) and from_unixtime($end_date)
or end_date between from_unixtime($start_date) and from_unixtime($end_date)
order by start_date";
Then, put together an array with the results:
$event_array = array();
while ($record = mysql_fetch_array($result)) {
$event_array[] = array(
'id' => $record['id'],
'title' => $record['title'],
'start' => $record['start_date'],
'end' => $record['end_date'],
'url' => $record['event_url'],
'allDay' => $record['all_day']
);
}
Finally, JSON encode it and echo it:
echo json_encode($event_array);
This seems to work. I'm not that familiar with the way date/time fields are handled in MySQL and PHP, so I'm not sure if I'm doing this in the most efficient manner.
You would need to implement a PHP page that retrieves event data from a MySQL database and returns it in JSON format. You would then use that URL as a JSON feed source for the calendar.
There is sample code on the FullCalendar GitHub repository.
And there is a demo showing how to listen to events if something changes in the calendar.
精彩评论