douji0073 2016-03-14 09:27
浏览 146
已采纳

MySQL数据进入FullCalendar

EDIT 2 I have the array at the correct format but nothing added to calendar:

enter image description here

EDIT

enter image description here

I want to get data from mysql and display it on fullcalendar. I have this PHP code:

<?php
//Set error reporting on
error_reporting(E_ALL);
ini_set("display_errors", 1);

//Include connection file
require_once('global.php');

//Json and PHP header
header('Content-Type: application/json');
$eventss = array();
$user = $_SESSION['username'];
$id_logged = $_SESSION['login_id'];

    $search_date = "SELECT * FROM appointment INNER JOIN patient ON appointment.patient_id = patient.id WHERE appointment.id_logged = :id_logged";
    $search_date_stmt = $conn->prepare($search_date);
    $search_date_stmt->bindValue(':id_logged', $id_logged);
    $search_date_stmt->execute();
    $search_date_stmt_fetch = $search_date_stmt->fetchAll();
    $search_date_stmt_count = $search_date_stmt->rowCount();

    foreach($search_date_stmt_fetch as $row)
    {
       $events[] = array( 'title' => $row['patient_name'], 'start' => date('Y-m-d',$row['date_app']), 'end' => date('Y-m-d',$row['date_app']), 'allDay' => false);
       array_push($events, $event);

    }

    echo json_encode($event);
?>

The array that should be returned to fullcalendar so it can display it should be like:

'id'=>'value', 'title'=>'my title', 'start'=>...etc

But what the array I am seeing in the XHR is like:

enter image description here

Here is fullcalendar script (no errors at the console):

    <script>
        (function ($) { 
            $(document).ready(function() {

              $('#calendar').fullCalendar({
                  eventSources: [

                    // your event source
                    {
                        url: 'fullcalendar/get-events.php',

                        error: function() {
                            alert('there was an error while fetching events!');
                        },
                        color: 'yellow',   // a non-ajax option
                        textColor: 'black' // a non-ajax option
                    }

                    // any other sources...

                ]
            });

          });
        })(jQuery);
    </script>
  • 写回答

3条回答 默认 最新

  • douxue7196 2016-03-14 10:16
    关注

    You are mixing $event, $events and $eventss (unused).

    It should read :

    foreach($search_date_stmt_fetch as $row) {
        $event = array( 'id' => $row['patient_id'], 'title' => $row['patient_name'], 'start' => date('Y-m-d',$row['date_app']), 'end' => date('Y-m-d',$row['date_app']), 'allDay' => false);
           array_push($events, $event);
    }
    
    echo json_encode($events);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考