fullcalendar 脚本调用 GET php 变量来获取 mysql 数据不起作用
fullcalendar script call a GET php variable to get mysql data doesn't work
我在使用这段代码时遇到问题:
<?php
// Require DB Connection
require_once('connect.php');
// Get ALl Event
$er = 1;
$sth = $dbh->prepare("SELECT * FROM events WHERE id_user = $er AND events.date BETWEEN ? AND ? ORDER BY events.date ASC");
$sth->execute(array($_GET['start'], $_GET['end']));
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);
?>
当我用这个值传递变量 $er
时,效果完美!但是当我通过 $_GET['cu']
失败时,有人可以告诉我发生了什么事吗?
注意:$_GET['cu']
是我从 URL http://..../?cu=1
中获取的值
并且此文件是从事件中的 Fullcalendar js 脚本调用的:
// Get all events stored in database
events: 'crud/getEvents.php',
谢谢大家,解决办法是:
到 main.js 添加此函数以获取 URL 数据:
function getParameterByName(name) {
name = name.replace(/[\[]/, "\[").replace(/[\]]/, "\]");
var regex = new RegExp("[\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
在活动中:
events: 'crud/getEvents.php?cu='+getParameterByName('cu'),
因此在文件 getEvents 中我们可以调用变量:
// Get ALl Event
$er = $_GET['cu'];
$sth = $dbh->prepare("SELECT * FROM events WHERE id_user = $er AND events.date BETWEEN ? AND ? ORDER BY events.date ASC");
我在使用这段代码时遇到问题:
<?php
// Require DB Connection
require_once('connect.php');
// Get ALl Event
$er = 1;
$sth = $dbh->prepare("SELECT * FROM events WHERE id_user = $er AND events.date BETWEEN ? AND ? ORDER BY events.date ASC");
$sth->execute(array($_GET['start'], $_GET['end']));
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);
?>
当我用这个值传递变量 $er
时,效果完美!但是当我通过 $_GET['cu']
失败时,有人可以告诉我发生了什么事吗?
注意:$_GET['cu']
是我从 URL http://..../?cu=1
并且此文件是从事件中的 Fullcalendar js 脚本调用的:
// Get all events stored in database
events: 'crud/getEvents.php',
谢谢大家,解决办法是:
到 main.js 添加此函数以获取 URL 数据:
function getParameterByName(name) {
name = name.replace(/[\[]/, "\[").replace(/[\]]/, "\]");
var regex = new RegExp("[\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
在活动中:
events: 'crud/getEvents.php?cu='+getParameterByName('cu'),
因此在文件 getEvents 中我们可以调用变量:
// Get ALl Event
$er = $_GET['cu'];
$sth = $dbh->prepare("SELECT * FROM events WHERE id_user = $er AND events.date BETWEEN ? AND ? ORDER BY events.date ASC");