开发者可以使用FullCalendar创建强大的日历日程应用,FullCalendar提供了丰富的选项设置和方法调用,使得开发者可以轻松的创建各种功能的日历程序。本文将结合实例使用PHP读取MySQl数据,显示在FullCalendar日历中。
<link rel="stylesheet" type="text/css" href="css/fullcalendar.css"><script src="js/jquery-1.9.1.min.js"></script><script src="js/jquery-ui-1.10.2.custom.min.js"></script><script src="js/fullcalendar.min.js"></script><div id='calendar'></div>$(function() { $('#calendar').fullCalendar({ header: {//设置日历头部信息 left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, firstDay:1,//每行第一天为周一 editable: true,//可以拖动 events: 'json.php' //事件数据 });});include_once('connect.php');//连接数据库$sql = "select * from calendar";$query = mysql_query($sql);while($row=mysql_fetch_array($query)){ $allday = $row['allday']; $is_allday = $allday==1?true:false; $data[] = array( 'id' => $row['id'],//事件id 'title' => $row['title'],//事件标题 'start' => date('Y-m-d H:i',$row['starttime']),//事件开始时间 'end' => date('Y-m-d H:i',$row['endtime']),//结束时间 'allDay' => $is_allday, //是否为全天事件 'color' => $row['color'] //事件的背景色 );}echo json_encode($data);我们将最终数据以json_encode()输出,然后,前端FullCalendar会解析json数据并显示在日历中,这些FullCalendar都替我们做好了,只管刷新前端页面看下效果吧。
最后附上demo中的MySQL数据表calendar的表结构:CREATE TABLE IF NOT EXISTS `calendar` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(100) NOT NULL, `starttime` int(11) NOT NULL, `endtime` int(11) DEFAULT NULL, `allday` tinyint(1) NOT NULL DEFAULT '0', `color` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8
零七网部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与零七网进行文章共享合作。