我的.js是:
$('#calendar').fullCalendar({
defaultView:'agendaWeek',
events: base+"v.php?acction=start",
.....
我在v.php中的查询是:
$query_visitas ='SELECT *,concat_ws(" ",name,surname) as title,
visit_id as id, concat_ws(" ",date_start,time_start) as start,
concat_ws(" ",date_end,time_end) as end FROM visits v
LEFT JOIN pacient p ON v.pacient_id = p.id
ORDER BY START';
感谢您的建议,因为我疯了!
答案 0 :(得分:1)
使用JSON从服务器获取FullCalendar事件时,显示的日历的start
和end
日期随请求一起发送。有关文档,请参阅 events as a JSON feed 。
您需要使用这些值并使用它们来过滤SELECT
返回的结果。它有点棘手,因为我们需要找到以下行:
start
之后和end
之前结束时间。start
之后和end
之前有一个开始时间。start
之前有一个开始时间,在end
之后有结束时间。您需要使用CONCAT_WS()
来形成有效的开始和结束日期时间字符串,然后使用DATE
将其转换为正确的STR_TO_DATE()
数据类型。
// FullCalendar V1 sends timestamps
$start = isset($_REQUEST['start'])? intval($_REQUEST['start']) : 0;
$end = isset($_REQUEST['end'])? intval($_REQUEST['end']) : 0;
// FullCalendar V2 sends ISO8601 date strings
$start = isset($_REQUEST['start'])? strtotime($_REQUEST['start']) : 0;
$end = isset($_REQUEST['end'])? strtotime($_REQUEST['end']) : 0;
// convert the timestamps to date strings for the SQL
$start_date = date('Y-m-d', $start);
$end_date = date('Y-m-d', $end);
// ordinarily you would use a prepared statement, but since you didn't specify a driver they variables are included inline - should be sanitized by date()`
$sql = <<<SQL
SELECT *,
visit_id as id,
CONCAT_WS(' ', name, surname) as title,
CONCAT_WS(' ', date_start, time_start) as start,
CONCAT_WS(' ', date_end, time_end) as end
FROM visits v
LEFT JOIN pacient p
ON v.pacient_id = p.id
WHERE
-- anything with an end between the start/end
STR_TO_DATE(CONCAT_WS(' ', date_end, time_end), '%Y-%m-%d %h:%i:%s') BETWEEN '{$start_date}' AND '{$end_date}'
OR
-- anything with an end between the start/end
STR_TO_DATE(CONCAT_WS(' ', date_start, time_start), '%Y-%m-%d %h:%i:%s') BETWEEN '{$start_date}' AND '{$end_date}'
OR
-- anything with a start before the start and an end after the end
(
STR_TO_DATE(CONCAT_WS(' ', date_start, time_start), '%Y-%m-%d %h:%i:%s') < '{$start_date}'
AND STR_TO_DATE(CONCAT_WS(' ', date_end, time_end), '%Y-%m-%d %h:%i:%s') > '{$end_date}'
)
ORDER BY start, end
SQL;