使用 FullCalendar 通过 jquery 列出数据库数据

List database data via jquery with FullCalendar

提问人:Luan Eduardo Moi 提问时间:5/25/2023 更新时间:5/26/2023 访问量:34

问:

我从数据库中返回一些字段,即: ID、标题、颜色、开始、结束、start_time、end_time和 OBS

在这种情况下,当在 php 文件中使用 while 注册字段并在 json 数组中返回时,以下示例如下:

$query_events = "SELECT id, title, color, start, end, start_time, end_time, obs FROM events";
$resultado_events = $pdo->prepare($query_events);
$resultado_events->execute();

$events = [];

while($row_events = $result_events->fetch(PDO::FETCH_ASSOC)){
     $id = $row_events['id'];
     $title = $row_events['title'];
     $color = $row_events['color'];
     $start = $row_events['start'];
     $end = $row_events['end'];
     $start_time = $row_events['start_time'];
     $end_time = $row_events['end_time'];
     $obs = $row_events['obs'];
    
     $events[] = [
         'id' => $id,
         'title' => $title,
         'color' => $color,
         'start' => $start,
         'end' => $end,
         'start_time' => $start_time,
         'time_end' => $time_end,
         'obs' => $obs
         ];
}

echo json_encode($events);

但是它甚至没有在页面的html中返回,甚至列表也是如此。仅返回 id、start 和 end

列出数据库中的记录,并在 FullCalender 中使用 jQuery 通过 JSON 数组显示

php jquery mysql

评论

0赞 Tat 5/25/2023
您是否在 HTML 页面上解码了 JSON 数据?
0赞 Luan Eduardo Moi 5/25/2023
你好!是的,我使用了 echo json_encode($events);
0赞 CBroe 5/25/2023
fullcalendar.io/docs/event-parsing - , , - 这些都不是默认属性。那么你有没有把Fullcalendar配置为使用这些?start_timetime_endobs

答:

1赞 HUNAIN AHMED 1002 5/26/2023 #1

'time_end' => $time_end应该是'time_end' => $end_time

use 代替$row_events = $resultado_events->fetch(PDO::FETCH_ASSOC)$row_events = $result_events->fetch(PDO::FETCH_ASSOC)

更正的代码:

$query_events = "SELECT id, title, color, start, end, start_time, end_time, obs FROM events";
$resultado_events = $pdo->prepare($query_events);
$resultado_events->execute();

$events = [];

while ($row_events = $resultado_events->fetch(PDO::FETCH_ASSOC)) {
    $id = $row_events['id'];
    $title = $row_events['title'];
    $color = $row_events['color'];
    $start = $row_events['start'];
    $end = $row_events['end'];
    $start_time = $row_events['start_time'];
    $end_time = $row_events['end_time'];
    $obs = $row_events['obs'];

    $events[] = [
        'id' => $id,
        'title' => $title,
        'color' => $color,
        'start' => $start,
        'end' => $end,
        'start_time' => $start_time,
        'end_time' => $end_time,
        'obs' => $obs
    ];
}

echo json_encode($events);