未通过mysql数据库中的id显示的事件

时间:2015-03-04 10:33:32

标签: javascript php jquery mysql fullcalendar

我有一个按钮列表,每个按钮都与一个人有关。当您单击按钮时,它将转到calendar.php?id=5(人员的ID)

我希望它显示他/她的日历,并在mysql数据库中注册他/她的id。

events.php正确报告我的数据库中的事件,但日历保持为空。我怎么能让它有效呢?

目前它会获得以下事件: (calendar.php)

<?php
$getid = $_GET['id'];
//echo $getid;
?>

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='css/fullcalendar.css' rel='stylesheet' />
<script src='js/moment.min.js'></script>
<script src='js/jquery.min.js'></script>
<script src='js/fullcalendar.min.js'></script>
<script>

    $(document).ready(function() {

        $('#calendar').fullCalendar({
            defaultDate: '2015-02-12',
            editable: false,
            allDayDefault: true,
            eventLimit: true, // allow "more" link when too many events
            events: "http://localhost/planning/events.php?id='$getid'"

        });

    });

</script>
<style>

    body {
        margin: 40px 10px;
        padding: 0;
        font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
        font-size: 14px;
    }

    #calendar {
        max-width: 900px;
        margin: 0 auto;
    }

</style>
</head>
<body>

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

</body>
</html>

(events.php)

<?php

$getid = $_GET['id'];

$json = array();

$requete = "SELECT id,title,start,end FROM absence WHERE id='$getid'";
$resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));
echo json_encode($resultat->fetchAll(PDO::FETCH_ASSOC));
?>

来自events.php的回复似乎很好。它为id 37显示了这个例子:

http://localhost/planning/events.php?id=37

&#13;
&#13;
[{"id":"37","title":"CONGE PAYE","start":"2013-05-10 00:00:00","end":"2013-05-10 00:00:00"},{"id":"37","title":"CONGE PAYE","start":"2013-07-22 00:00:00","end":"2013-08-11 00:00:00"},{"id":"37","title":"CONGE PAYE","start":"2013-12-19 00:00:00","end":"2014-01-07 00:00:00"},{"id":"37","title":"CONGE PAYE","start":"2012-07-30 00:00:00","end":"2012-08-09 00:00:00"},{"id":"37","title":"CONGE PAYE","start":"2012-05-11 00:00:00","end":"2012-05-13 00:00:00"},{"id":"37","title":"CONGE PAYE","start":"2014-08-11 00:00:00","end":"2014-08-24 00:00:00"},{"id":"37","title":"CONGE PAYE","start":"2014-11-10 00:00:00","end":"2014-11-16 00:00:00"},{"id":"37","title":"CONGE PAYE","start":"2014-06-10 00:00:00","end":"2014-06-11 00:00:00"},{"id":"37","title":"CONGE PAYE","start":"2014-12-24 00:00:00","end":"2015-01-11 00:00:00"},{"id":"37","title":"CONGE SANS SOLDE","start":"2012-08-10 00:00:00","end":"2012-08-15 00:00:00"}]
&#13;
&#13;
&#13;

可悲的是,日历仍然是空的。

2 个答案:

答案 0 :(得分:0)

您需要确定一些事项:

  1. 您在日历中的日期必须与活动中的日期一致。
  2. 您需要为没有时间的活动设置allDay(请参阅Event Object docs)。或者,您可以设置allDayDefault
  3. 出于演示目的,请检查this jsfiddle。我已经使用了你的更新中的json。以下是我的更改:

    1. 添加defaultDate: '2013-05-10',以查看一个事件(json对象中的第一个)
    2. 在2013-05-10上为活动添加了allDay: true
    3. 为2013-07-22和2013-08-11之间发生的事件添加了allDay: true

    4. 更新

      根据您的评论,您的查询存在问题。改变这个:

      $requete = "SELECT id,title,start,end FROM absence WHERE id='$getid'";
      

      进入这个:

      $requete = "SELECT id,title,start,end FROM absence WHERE id='" . $getid . "'";
      

      您还应该查看与mysql injection相关的教程。

答案 1 :(得分:0)

好的...... geofrey做了我在上一条评论中建议的内容......换句话说就是重新设计你的数据库。我看到你已经放置了一个事件来源...所以我们在那里很好。 修复数据库...我认为这应该没问题