0

我的数据库中的事件未显示在我的完整日历上。我使用了我在网上看到的示例中的代码,所以请耐心等待我现在拥有的代码。我将不胜感激从你们那里得到的所有帮助。谢谢!

<script>
                $(document).ready(function() {
                // page is now ready, initialize the calendar...

                $('#calendar').fullCalendar({
                    header: {
                        left: 'prev,next today',
                        center: 'title',
                        right: 'month,agendaWeek,agendaDay'
                    },editable: false,

                    events: "json_events.php",

                    eventDrop: function(event, delta) {
                            alert(event.title + ' was moved ' + delta + ' days\n' +
                            '(should probably update your database)');
                    },

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

json_events.php

<?php
    include 'connect.php';
    session_start();
    $result = mysql_query("SELECT ID, title, startDate AS startDate FROM events");
    mysql_close();
    $events = array();
    while ($row=mysql_fetch_array($result)){
       $title = $row['title'];
       $eventsArray['id'] =  $row['ID'];
       $eventsArray['title'] = $title;
       $eventsArray['startDate'] = $row['startDate']; 
       $events[] = $eventsArray;
     }
  echo json_encode($events);
?>
4

1 回答 1

2
<?php
    include 'connect.php';
    session_start();
    $result = mysql_query("SELECT ID, title, startDate AS startDate FROM events");
    mysql_close();
    $events = array();
    while ($row=mysql_fetch_array($result)){            
        $id =  $row['ID'];
        $title = $row['title'];
        $start = $row['startDate']; 

        $events = array(
        'id' =>  "$id",
        'title' => "$title",
        'start' => "$start"
        );

    }
    echo json_encode($events);
?>

That should work for you. If you do not want the even to be all day just add 'allDay' => "" after the start statement.

于 2012-09-02T15:56:05.193 回答