无法在Fullcalendar上显示数据库

时间:2013-10-29 02:39:36

标签: php fullcalendar

我目前正在尝试为FullCalendar创建JSON Feed。我目前有一个工作示例,但是输出并没有将我的数据库放入日历中。有人有主意吗?我现在一直坚持这个......

在我的代码中:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <link href='css/fullcalendar.css' rel='stylesheet' />
  <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>
  <script>

$(document).ready(function() {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var calendar = $('#calendar').fullCalendar({
        editable: true,

        events : "test1.php",
    eventClick: function(event) {
            // opens events in a popup window
            window.open(event.url, '', 'width=700,height=600');
            return false;
        },

        loading: function(bool) {
            if (bool) {
                $('#loading').show();
            }else{
                $('#loading').hide();
            }
        }   

    });

});

   </script>
    <style>

body {
    margin-top: 40px;
    text-align: center;
    font-size: 14px;
    font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
    }

#calendar {
    width: 900px;
    margin: 0 auto;
    }

   </style>
   </head>
    <body>
   <div id='calendar'></div>
   </body>
   </html>

test1.php的代码

 $link = mysql_connect('localhost','root','abc123');
 if (!$link) { die('Could not connect: ' . mysql_error()); }
 mysql_select_db('trainingcourse');

 $result = mysql_query("SELECT * FROM tbl_course ");

 Initializes a container array for all of the calendar events
 $jsonArray = array();

  while($row = mysql_fetch_array($result, MYSQL_ASSOC))
  {
   $eventtest = $row['courseid'];
   $startdate = $row['startdate'];
   $starttime = $row['starttime'];
     $enddate = $row['enddate'];
     $endtime = $row['endtime'];

    // Stores each database record to an array
    $buildjson = array('courseid' => "$eventtest", 'startdate' => "$startdate", 'enddate' => "$enddate", 'allday' => false);

    // Adds each array into the container array
    array_push($jsonArray, $buildjson);
      }
    // Output the json formatted data so that the jQuery call can read it
    echo json_encode($jsonArray);
       ?>

无法在日历上显示。

非常感谢你的帮助。

2 个答案:

答案 0 :(得分:0)

你可以尝试一下吗?

<?php 
 $link = mysql_connect('localhost','root','abc123');
 if (!$link) { die('Could not connect: ' . mysql_error()); }
 mysql_select_db('trainingcourse',$link);

 $result = mysql_query("SELECT * FROM tbl_course ");


  while($row = mysql_fetch_assoc($result, MYSQL_ASSOC))
  {
   $eventtest = $row['courseid'];
   $startdate = $row['startdate'];
   $starttime = $row['starttime'];
     $enddate = $row['enddate'];
     $endtime = $row['endtime'];

    // Stores each database record to an array
    $buildjson[] = array(
                         'courseid'  => $eventtest, 
                         'startdate' => $startdate, 
                         'enddate'   => $enddate, 
                         'allday'    => false
                         );


  }
    // Output the json formatted data so that the jQuery call can read it
    echo json_encode($buildjson);
       ?><br>

希望它有效。还请尝试打印结果 print_r($ buildjson);

答案 1 :(得分:0)

试试这个,它对我有用

关于PHP代码: header('Content-Type:application / json');

echo json_encode($ jsonArray);

关于你的html代码: 将此选项添加到您的日历:         eventSources:[

            // your event source
            {
                url: 'url/of/your/jsonphp',
                type: 'POST',
                data: {
                    custom_param1: 'something',
                    custom_param2: 'somethingelse'
                },
                error: function() {
                    alert('there was an error while fetching events!');
                },
                color: '#dadada',
                textColor: '#000000'
            }