PHP, jQuery FullCalendar - Array not reading variable

Viewed 68

I am studying FullCalendar and I have a PHP file named courts.php which has events: 'load.php' in it. In load.php, I am trying to insert an id through GET. The goal is to have the calendar only display the events of the court clicked.

Here's how I wrote the event in courts.php:

events: 'load.php'

This is what load.php contains:

$data = array();
$currentgymid = $_GET['id'];
$query = "SELECT * FROM events WHERE gymID = :gymid ORDER BY id";
$statement = $connect->prepare($query);
$statement->execute(
    array(
        ':gymid' => $currentgymid
    )
);
$result = $statement->fetchAll();
foreach($result as $row)
{
   $data[] = array(
       'id'   => $row["id"],
       'email'   => $row["email"],
       'start'   => $row["start_event"],
       'end'   => $row["end_event"]
      );
}
echo json_encode($data);

I have also tried using sessions but does not seem to work. However, assigning an integer directly works perfectly. Example:

array(':gymid' => 46)

EDIT: Here's some more of the code. Anything before and after this is irrelevant to load.php

var calendar = $('#calendar').fullCalendar({
    contentHeight: "auto",
    slotMinutes: 120,
    slotLabelIntervalDuration: "00:30",
    timezone: 'local', 
    defaultView: 'agendaWeek',
    minTime: "<?php echo $open; ?>",
    maxTime: "<?php echo $close; ?>",
    slotDuration: '00:60:00',
    displayEventTime: true,
    editable: false,
    eventStartEditable: false,
    allDaySlot: false,
    selectOverlap: false,
    timeGridEventMinHeight: 1280,
    validRange:{
        start: today
    },

    header:{
     left:'prev,next today',
     center:'title',
     right:''
    },

    events: 'load.php',
    selectable:true,
    selectHelper:true,
1 Answers

Please try changing (in your javascript)

 events: 'load.php',

to

 events: 'load.php?id=46',

and then change the "46" by passing your actual ID (use extraParams like the following)

 events: {
    url: 'load.php',
    method: 'GET',
    extraParams: {
      id: '<?php echo htmlspecialchars($id, ENT_QUOTES);?>',

    },
Related