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
12 days ago.

Hello,

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() {
dp.events.load("backend_events.php");
}

loadEvents();

along with backend_events.php page:

<?php

$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

$stmt->execute();
$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 dp.events.load.
Can anyone help me with this?
Thank you.

Answer posted by Knight
12 days ago.

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

Comment posted by John C
12 days ago.

Thank you, this solution worked!

New Reply
This reply is
Your name (optional):