为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

收到一只叮咚 2024-01-03 15:12:50
我一直致力于使用资源列开发 fullCalendar 拖放事件。现在,我已经对可拖动事件区域进行了硬编码;现在尝试从数据库中获取它。该数据库以前有两个表 - 资源和事件。事件被删除到日历后,会在事件表中更新。资源列是从数据库中获取的,为了添加新资源,我构建了一个房间按钮,它将新资源保存在资源表中。到目前为止,我的主文件中只有五个可拖动事件,但现在我也正在努力从数据库中获取这些事件。因此,我在数据库中又创建了一个名为draggableevents 的表。该表包含两列 id 和 EventName。这是代码:拖拽事件.php<?phprequire "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 文件似乎没有加载。我在网络面板中没有看到它,因此没有与之相关的错误。
查看完整描述

1 回答

?
皈依舞

TA贡献1851条经验 获得超3个赞

有一些明显的逻辑问题,但与 fullCalendar 没有太大关系:

1)我在之前的问题中多次提到过这一点:return当您不在函数内部时不返回值。您认为您到底要把它返回到哪里?require没有办法

2)即使有效,您也永远不会返回任何事件,因为您的while循环已关闭并且不执行任何操作。

3)$result无论如何都会超出 while 循环之外的范围。

4)你从不执行你的查询

5) 你没有知道echo活动名称。

您需要将所有数据库结果放入一个数组中,然后循环该数组以生成与fc-event数组中的条目一样多的 div。

这是一种方法 - 我将draggableevents.php 的功能放入一个函数中,您可以在需要时调用它。

拖拽事件.php

<?php

require "connection.php";


function getDraggableEvents() {

  $conn = DB::databaseConnection();

  $sql = "Select * FROM DraggableEvents";

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

  $stmt->execute();

  $results = array();

  while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

   $results[] = $row;

  }

  return $results;

}

?>

表单.php


<html>

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

<body>

  <div id='external-events'>

    <p>

      <strong>Draggable Events</strong>

    </p>


    <?php

    require 'draggableevents.php';

    $events = getDraggableEvents();

    foreach ($events as $event)

    {

    ?>

      <div class='fc-event'><?php echo $event['EventName']; ?></div>

    <?php

    }

    ?>


    <p>

      <input type='checkbox' id='drop-remove' />

      <label for='drop-remove'>remove after drop</label>

    </p>

  </div>

  <div id='calendar-container'>

    <div id='calendar'></div>

   </div>

</body>

</html>


查看完整回答
反对 回复 2024-01-03
  • 1 回答
  • 0 关注
  • 102 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信