英文:
How can I Post current url parameter to fullcallender fetch event
问题
$rmid = 1 //从当前URL获取此ID;
英文:
Hie there, I kindly need help posting or rather getting id of the current url to fetch events in fullcalendar. The callendar is on a page with a url like this www.mysite.com/rooms?id=1.
I would like to fetch events based on that id. I tried using PHP sessions it didnt work
Below is my PHP Code
//$rmid = (int)$_POST['rmid'];
$rmid = 1 //Get this id from the current url;
$conn = $pdo->open();
$stmt = $conn->prepare("SELECT *, checkin as start, checkout as end FROM reservation WHERE room_id= :rmid ORDER BY id ");
$stmt->execute(['rmid' =>$rmid]);
$results = array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$results[] = $row;
}
$stmt->closeCursor();
$pdo->close();
echo json_encode($results);
Here is the fullcalendar I'm using
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
editable: false,
events: "fetch-event.php",
displayEventTime: false,
eventRender: function (event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
},
selectable: false,
selectHelper: true,
});
});
答案1
得分: 1
我找到了一个有效的解决方案,我之前在页面上将我的 $_SESSION 放在 foreach 循环中,现在在当前页面上是这样的:
$_SESSION['rid'] = (int)$_GET['id'];
然后我的 fetch 事件如下:
$rmid = (int)$_SESSION['rid'];
英文:
I found a working solution, I was putting my $_SESSION in foreach loop on the page before
Rather its like this on the current page
$_SESSION['rid'] = (int)$_GET['id'];
then my fetch-event like this,
$rmid = (int)$_SESSION['rid'];
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论