如何从 fullCalendar 的数据库中获取可拖动事件区域?

我一直致力于使用资源列开发 fullCalendar 拖放事件。现在,我已经对可拖动事件区域进行了硬编码;现在尝试从数据库中获取它。该数据库以前有两个表 - 资源和事件。事件被删除到日历后,会在事件表中更新。资源列是从数据库中获取的,为了添加新资源,我构建了一个房间按钮,它将新资源保存在资源表中。到目前为止,我的主文件中只有五个可拖动事件,但现在我也正在努力从数据库中获取这些事件。因此,我在数据库中又创建了一个名为draggableevents 的表。该表包含两列 id 和 EventName。


这是代码:


拖拽事件.php


<?php

require "connection.php";

$conn = DB::databaseConnection();

$conn->beginTransaction();

$sql = "Select * FROM DraggableEvents";

$stmt = $conn->prepare($sql);

if ($stmt->execute()) {

while($result = $stmt->fetch(PDO::FETCH_ASSOC));

return $result;

} else {

return null;

}

?>

表单.php


<head>

<link href='https://unpkg.com/@fullcalendar/core@4.4.0/main.min.css' rel='stylesheet' />

<link href='https://unpkg.com/@fullcalendar/daygrid@4.4.0/main.min.css' rel='stylesheet' />

<link href='https://unpkg.com/@fullcalendar/timegrid@4.4.0/main.min.css' rel='stylesheet' />

<script src='https://unpkg.com/@fullcalendar/core@4.4.0/main.min.js'></script>

<script src='https://unpkg.com/@fullcalendar/interaction@4.4.0/main.min.js'></script>

<script src='https://unpkg.com/@fullcalendar/daygrid@4.4.0/main.min.js'></script>

<script src='https://unpkg.com/@fullcalendar/timegrid@4.4.0/main.min.js'></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

<link href='https://unpkg.com/@fullcalendar/timeline@4.4.0/main.min.css' rel='stylesheet' />

<link href='https://unpkg.com/@fullcalendar/resource-timeline@4.4.0/main.min.css' rel='stylesheet' />

 <script src='https://unpkg.com/@fullcalendar/timeline@4.4.0/main.min.js'></script>

 <script src='https://unpkg.com/@fullcalendar/resource-common@4.4.0/main.min.js'></script>

 <script src='https://unpkg.com/@fullcalendar/resource-timeline@4.4.0/main.min.js'></script>

 <link rel="stylesheet" href="css/main.css" media="all">

 <link href="main.css" rel="stylesheet">

 <script src='main.js'></script>

</head>


上面的代码会产生一个空白的可拖动事件区域。刷新页面时,draggableevents.php 文件似乎没有加载。我在网络面板中没有看到它,因此没有与之相关的错误。


收到一只叮咚
浏览 45回答 1
1回答

皈依舞

有一些明显的逻辑问题,但与 fullCalendar 没有太大关系:1)我在之前的问题中多次提到过这一点:return当您不在函数内部时不返回值。您认为您到底要把它返回到哪里?require没有办法2)即使有效,您也永远不会返回任何事件,因为您的while循环已关闭并且不执行任何操作。3)$result无论如何都会超出 while 循环之外的范围。4)你从不执行你的查询5) 你没有知道echo活动名称。您需要将所有数据库结果放入一个数组中,然后循环该数组以生成与fc-event数组中的条目一样多的 div。这是一种方法 - 我将draggableevents.php 的功能放入一个函数中,您可以在需要时调用它。拖拽事件.php<?phprequire "connection.php";function getDraggableEvents() {&nbsp; $conn = DB::databaseConnection();&nbsp; $sql = "Select * FROM DraggableEvents";&nbsp; $stmt = $conn->prepare($sql);&nbsp; $stmt->execute();&nbsp; $results = array();&nbsp; while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {&nbsp; &nbsp;$results[] = $row;&nbsp; }&nbsp; return $results;}?>表单.php<html><head>&nbsp; <link href='https://unpkg.com/@fullcalendar/core@4.4.0/main.min.css' rel='stylesheet' />&nbsp; <link href='https://unpkg.com/@fullcalendar/daygrid@4.4.0/main.min.css' rel='stylesheet' />&nbsp; <link href='https://unpkg.com/@fullcalendar/timegrid@4.4.0/main.min.css' rel='stylesheet' />&nbsp; <script src='https://unpkg.com/@fullcalendar/core@4.4.0/main.min.js'></script>&nbsp; <script src='https://unpkg.com/@fullcalendar/interaction@4.4.0/main.min.js'></script>&nbsp; <script src='https://unpkg.com/@fullcalendar/daygrid@4.4.0/main.min.js'></script>&nbsp; <script src='https://unpkg.com/@fullcalendar/timegrid@4.4.0/main.min.js'></script>&nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>&nbsp; <link href='https://unpkg.com/@fullcalendar/timeline@4.4.0/main.min.css' rel='stylesheet' />&nbsp; <link href='https://unpkg.com/@fullcalendar/resource-timeline@4.4.0/main.min.css' rel='stylesheet' />&nbsp; <script src='https://unpkg.com/@fullcalendar/timeline@4.4.0/main.min.js'></script>&nbsp; <script src='https://unpkg.com/@fullcalendar/resource-common@4.4.0/main.min.js'></script>&nbsp; <script src='https://unpkg.com/@fullcalendar/resource-timeline@4.4.0/main.min.js'></script>&nbsp; <link rel="stylesheet" href="css/main.css" media="all">&nbsp; <link href="main.css" rel="stylesheet">&nbsp; <script src='main.js'></script></head><body>&nbsp; <div id='external-events'>&nbsp; &nbsp; <p>&nbsp; &nbsp; &nbsp; <strong>Draggable Events</strong>&nbsp; &nbsp; </p>&nbsp; &nbsp; <?php&nbsp; &nbsp; require 'draggableevents.php';&nbsp; &nbsp; $events = getDraggableEvents();&nbsp; &nbsp; foreach ($events as $event)&nbsp; &nbsp; {&nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; <div class='fc-event'><?php echo $event['EventName']; ?></div>&nbsp; &nbsp; <?php&nbsp; &nbsp; }&nbsp; &nbsp; ?>&nbsp; &nbsp; <p>&nbsp; &nbsp; &nbsp; <input type='checkbox' id='drop-remove' />&nbsp; &nbsp; &nbsp; <label for='drop-remove'>remove after drop</label>&nbsp; &nbsp; </p>&nbsp; </div>&nbsp; <div id='calendar-container'>&nbsp; &nbsp; <div id='calendar'></div>&nbsp; &nbsp;</div></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5