完整日历始终显示所有事件

时间:2014-04-14 12:18:12

标签: php sql fullcalendar

我的完整日历存在问题,因此当我想添加活动时,一切正常 我的问题出现在类别中。因此,当日历加载时,它会显示所有完美的事件。但是,当我更改类别选择中的类别时,它仍会显示每个事件。我真的不知道为什么它没有更新,因为当我执行时:

$this->result = mysqli_query($this->connection,
"SELECT * FROM $this->table WHERE $this->condition");

然后:

var_dump($this->result);

我有很多事件:

object(mysqli_result)#3 (5)
{
   ["current_field"]=> int(0)
   ["field_count"]=> int(9)
   ["lengths"]=> NULL 
   ["num_rows"]=> int(3)
   ["type"]=> int(0) 
}

3在这里,它仍然显示8个事件。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我刚刚找到了如何使用它。

问题是我从我的数据库获得了sql结果,而不是包含所有数据的json数组。所以我只是将我的日历对象构建结果传递给我的json函数:

        /**
    * Function To Transform MySQL Results To jQuery Calendar Json
    * Returns converted json
    */
    public function json_transform($calendar,$js = true)
    {

        while($this->row = mysqli_fetch_array($calendar->result, MYSQLI_ASSOC))
        {
             // Set Variables Data from DB
             $event_id = $this->row['id'];
             $event_title = $this->row['title'];
             $event_description = $this->row['description'];
             $event_start = $this->row['start'];
             $event_end = $this->row['end'];
             $event_allDay = $this->row['allDay'];
             $event_color = $this->row['color'];
             $event_url = $this->row['url'];
             $event_society = $this->row['category'];

             if($js == true) 
             {
                 // JS MODE
                 // When allDay = false the allDay options appears on the script, when its true it doesnot appear 
                 if($event_url == 'false' && $event_allDay == 'false')
                 {
                     // Build it Without URL & allDay

                     // Stores Each Database Record To An Array (Without URL)
                    $build_json = array('id' => $event_id, 'title' => $event_title, 'description' => $event_description, 'start' => $event_start, 'end' => $event_end, 'allDay' => $event_allDay, 'color' => $event_color);

                    // Adds Each Array Into The Container Array
                    array_push($this->json_array, $build_json);

                 } elseif($event_url == 'false' && $event_allDay == 'true') {

                     // Build it Without URL 

                     // Stores Each Database Record To An Array (Without URL)

                    $build_json = array('id' => $event_id, 'title' => $event_title, 'description' => $event_description, 'start' => $event_start, 'end' => $event_end, 'color' => $event_color);

                    // Adds Each Array Into The Container Array
                    array_push($this->json_array, $build_json);


                 } elseif($event_url == 'true' && $event_allDay == 'false') {

                     // Built it Without URL & allDay True

                    // Stores Each Database Record To An Array
                    $build_json = array('id' => $event_id, 'title' => $event_title, 'description' => $event_description, 'start' => $event_start, 'end' => $event_end, 'allDay' => $event_allDay, 'color' => $event_color, 'url' => $event_url);

                    // Adds Each Array Into The Container Array
                    array_push($this->json_array, $build_json);

                 } else {

                     if($event_allDay == 'false') {
                        // Built it With URL & allDay false

                        // Stores Each Database Record To An Array
                        $build_json = array('id' => $event_id, 'title' => $event_title, 'description' => $event_description, 'start' => $event_start, 'end' => $event_end, 'allDay' => $event_allDay, 'color' => $event_color, 'url' => $event_url);

                        // Adds Each Array Into The Container Array
                        array_push($this->json_array, $build_json);
                     } else {
                        // Built it With URL & allDay True

                        // Stores Each Database Record To An Array
                        $build_json = array('id' => $event_id, 'title' => $event_title, 'description' => $event_description, 'start' => $event_start, 'end' => $event_end, 'color' => $event_color, 'url' => $event_url);

                        // Adds Each Array Into The Container Array
                        array_push($this->json_array, $build_json);  
                     }


                 }
             }
       }

然后使用此数组我只需刷新我的日历:

            if(opt.filter == true)
        {
            $(opt.formFilterSelector).on('change', function(e) 
            {

                 selected_value = $(this).val();

                 construct = 'filter='+selected_value;
                 $.post('includes/cal_events.php', construct, function(response) 
                {
                     $(opt.calendarSelector).fullCalendar('removeEvents');
                     var obj = $.parseJSON(response);
                     $(opt.calendarSelector).fullCalendar( 'addEventSource', obj);

                });                  
                 e.preventDefault();  
            });
        }

cal_events.php文件调用json函数。 您需要将json数组转换为javascript: var obj = $ .parseJSON(response); 以使其正常工作。

希望这会有所帮助。