将当前URL参数发布到fullcalendar fetch事件中。

huangapple go评论59阅读模式
英文:

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'];

huangapple
  • 本文由 发表于 2023年5月22日 15:31:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76303896.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定