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

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条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题