2016-03-04 51 views
0

我试图从MySQL数据库中取数据到日历中。 (FullCalendar插件) 我想将提取的数据作为json提要发送以显示在日历上。从数据库中提取事件到FullCalendar

这是显示的事件我的Javascript代码:

events: { 
     url: 'http://localhost/Hotel/event_source.php', 
     error: function() { 
     alert('There was an error while fetching events.'); 
     } 

这是event_source.php页面,在这里我从数据库中获取数据:

<?php 
    include('hoteldb.php'); 
    global $conn; 
    if($stmt = $conn->prepare("SELECT title, startDate, endDate FROM event")) 
    { 
     $stmt->execute(); 
     $stmt->bind_result($title, $startDate, $endDate); 
     while ($stmt->fetch()) 
     { 
      $rows[] = array('title' => $title, 'startDate' => $startDate, 'endDate' => $endDate); 
     } 
     $stmt->close(); 
     echo json_encode($rows); 
     } 
?> 
+0

那么你的要求是什么? – rahul

+0

事件未在日历上显示 – user100000001

回答

0

的代码应该是修改如下。声明方法将返回下一行,你必须抓住它,如下所示。还有,这些列是按照我在下面的代码中显示的进行访问的。

$rows=array(); 
while ($row=$stmt->fetch()) 
{ 
    $rows[] = array('title' => $row['title'], 'startDate' => $row['startDate'], 'endDate' => $row['endDate']); 
} 
0

试试下面一个在while循环

“标题”和“开始”必须是有在事件日历加载。

while ($stmt->fetch()) 
{ 
    $rows[] = array('title' => $title, 'start' => date('Y-m-d H:i:s', strtotime($startDate)), 'end' => date('Y-m-d H:i:s', strtotime($endDate))); 
}