我正在使用FullCalendar jquery插件在我的页面上显示日历。我现在正试图弄清楚如何使用我自己的事件填充日历。我有一些代码循环我的查询结果并构建所有事件的$json_array
。这似乎有效,因为当我将数组输出到屏幕时,我可以看到我的事件并且它们看起来格式正确,如下所示:
[eventData] => Array
(
[0] => Array
(
[title] => 09:30 AM Hearing-950 Boundary Rd, South Glengarry PC540 H#559588-Council Chambers - 6 Oak St, Lancaster
[start] => 2014-04-29
)
[1] => Array
(
[title] => 09:30 AM Hearing-6-12 Park St, Brockville PC340 H#559597-Council Chambers - 1 King St W., Brockville
[start] => 2014-04-30
)
[2] => Array
(
[title] => 09:30 AM Hearing-1340 Kingston Rd, Pickering PC430 H#558975-Council Chambers, One The Esplanade, Pickering
[start] => 2014-04-01
)
)
除了构建$json_array
之外,我的示例代码还构建了一个名为$eventString
的字符串,看起来它也可以用作日历的事件源。以下是构建$json_array
和$eventString
:
<?php
$qryEvents = $this->db->query(" SELECT date(tbldeadlines.Date) AS D,
time_format(tbldeadlines.HearingStartTime, '%H:%i %p') AS S,
tbldeadlines.Type AS T,
tbldeadlines.`Property#` AS P,
tblproperties.`Property Address` AS A,
tblmunicipalities.MunicipalityName AS M,
tblproperties.`Property Owner` AS O,
tbldeadlines.HearingNotes AS N,
tbldeadlines.HearingNumber AS H,
format(tblproperties.PC,0) AS PC,
tblpropertycodes.`SIMPLE PC NAME` AS PCN
FROM tbldeadlines INNER JOIN tblproperties ON tbldeadlines.`Property#` = tblproperties.`Property#`
INNER JOIN tblmunicipalities ON tblproperties.County = tblmunicipalities.MunicipalitiesCounty
INNER JOIN tblpropertycodes ON tblproperties.PC = tblpropertycodes.PC
WHERE 1 {$whereCond}
GROUP BY P, D, T, A, N, H, S");
$evntArray = $qryEvents->result_array();
$eventString = "";
if(!empty($evntArray)){
$json_array = array();
$eventString .= "[" ;
foreach($evntArray as $row){
$json_array[] = array("title"=>addslashes($row['S'])." ".addslashes($row['T'])."-".addslashes($row['A']).", ".addslashes($row['M'])." PC".addslashes($row['PC'])." H#".addslashes($row['H'])."-".addslashes($row['N']), "start"=> date('Y-m-d',strtotime($row['D'])));
$eventString .= "{title:'".addslashes($row['N'])."',start:'".date('Y-m-d',strtotime($row['D']))."'},";
}
$eventString .= substr($eventString,0,-1);
$eventString .= "]";
}
if($_GET['start'] != "" && $_GET['end'] != ""){
echo json_encode($json_array);
}
$data['eventData'] = $json_array;
$data['calurl'] = 'http://mysite.ca/admin/view';
$this->load->view('pts_template', $data);
?>
我的问题是我不知道如何将结果记入日历。如何初始化日历并引用页面上已有的数组?我应该使用哪个,$json_array
或$eventString
?
感谢您提出的任何想法。