DatePicker和FullCalendar总是短短一天

时间:2014-10-21 11:46:06

标签: jquery mysql datepicker fullcalendar

我正在使用此代码将预订插入数据库。

的DatePicker

<script type='text/javascript'>
  $(document).ready(function() {
     $('#dp1, #dp2').datepicker({
         autoclose: true,
         format: "yyyy-mm-dd"
     });
  });
</script>

SQL

<?php
session_start();

$dbh = new PDO('mysql:host=localhost;dbname=calendar', 'user', 'pass');

$stmt = $dbh->prepare("INSERT INTO bookings (forename, surname, badge, colour, start, end) VALUES (:forename, :surname, :badge, :colour, STR_TO_DATE(:dp1,'%Y-%m-%d'), STR_TO_DATE(:dp2,'%Y-%m-%d'))");

foreach ($_POST as $key => $value) {
    $stmt->bindParam("$key", $_POST[$key]);
}

$stmt->execute();

header("Location: /");
?>

SQL表

mysql> SELECT * FROM bookings;
+----+----------+---------+-------+--------+---------------------+---------------------+---------------------+
| id | forename | surname | badge | colour | start               | end                 | timestamp           |
+----+----------+---------+-------+--------+---------------------+---------------------+---------------------+
|  1 | John     | Doe     | 1     | black  | 2014-10-27 00:00:00 | 2014-10-31 00:00:00 | 2014-10-21 13:11:50 |
+----+----------+---------+-------+--------+---------------------+---------------------+---------------------+
1 row in set (0.00 sec)

这是周一至周五的预订,但显示为周一至周四。

enter image description here

SQL查询

<?php
$dbh = new PDO('mysql:host=localhost;dbname=calendar', 'user', 'pass');

$stmt = $dbh->prepare("SELECT * FROM bookings");

$stmt->execute();

$return_array = array();
$event_array;

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

  $event_array['id'] = $row['id'];
  $event_array['title'] = $row['forename'] ." ". $row['surname'];
  $event_array['start'] = $row['start'];
  $event_array['end'] = $row['end'];
  $event_array['allDay'] = true;

  $event_array['className'] = $row['colour'];

  array_push($return_array, $event_array);
}

echo json_encode($return_array);
?>

FullCalendar

<script type='text/javascript'>
  $(document).ready(function() {
    $('#calendar').fullCalendar({
      eventSources: [
        {
          url: 'data.php',
          type: 'POST'
        }
      ]
    })
  });
</script>

问题

例如,如果我选择开始日期为星期一,结束日期为星期五,则日历会显示从星期一开始到星期四而非星期五结束的预订。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是因为events数组中的end是独占的。

另请参阅文档:http://fullcalendar.io/docs/event_data/Event_Object/

  

活动结束的专属日期/时间。可选的。

     

Moment-ish输入,类似于ISO8601字符串。整个API这个   将成为真正的Moment对象。

     

这是活动结束后的那一刻。例如,   如果活动的最后一整天是星期四,则独家结束   活动将于周五00:00:00举行!