2011-07-15 90 views
3

我正在考虑在网站上使用FullCalendar作为事件日历。全日历事件数据

我的问题:是否有任何文档或使用PHP/MySQL存储访问事件数据的例子?

谢谢!

回答

2

我也是这么做的,我希望有更完整的PHP/MySQL方面的例子,因为我通常是一个ASP.NET/MSSQL人员,所以我不得不花费更多时间比我想要的一些基本的东西。这是我做了什么的大纲。这很基本。

首先,我创建MySQL中的表看起来像这样:

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; 

于是,我写了一个名为JSON-events.php一个PHP程序,这是我作为日历事件源。在这个程序中,你首先需要获得的开始和结束日期为当前显示的日历:

$start_date = $_GET['start']; 
$end_date = $_GET['end']; 

然后,你需要运行一个SQL查询来获取事件,在该窗口:

$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"; 

然后,放在一起的阵列的结果:

$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'] 
    ); 
} 

最后,JSON编码它和回声它:

echo json_encode($event_array); 

这似乎工作。我不太熟悉在MySQL和PHP中处理日期/时间字段的方式,所以我不确定我是否以最有效的方式执行此操作。