search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to load events only from a specific userID

Asked by John C
2 years ago.


I'm building a website where the user can login and add, update and remove events.
The events that are loaded at the start have to be the ones from that specific user.
Both the events and the user are loaded from my database.

I'm using this code on my index page:

function loadEvents() {"backend_events.php");


along with backend_events.php page:


$stmt = $db->prepare('SELECT * FROM events WHERE NOT ((end <= :start) OR (start >= :end)) AND userID = :userID');

$stmt->bindParam(':start', $_GET['start']);
$stmt->bindParam(':end', $_GET['end']);
$stlt->bindParam(':userID', $_GET['userID']); //Not sure if this is the correct way to do

$result = $stmt->fetchAll();

class Event {}
$events = array();

foreach($result as $row) {
$e = new Event();
$e->id = $row['id'];
$e->text = $row['name'];
$e->start = $row['start'];
$e->end = $row['end'];
$events[] = $e;

header('Content-Type: application/json');
echo json_encode($events);


I have no idea what to do because I can't add the extra value (userID) in
Can anyone help me with this?
Thank you.

Answer posted by Knight
2 years ago.

PHP is not my primary language, but maybe you can try adding the userId as a parameter to the backend url.
So"backend_events.php"); becomes:"backend_events.php?userid=1");

Comment posted by John C
2 years ago.

Thank you, this solution worked!

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.