<?php
require_once __DIR__ . '/../../connect.php';

$rideId = filterRequest("rideId");

$sql = "SELECT
    *
FROM
    `passengerlocation` pl
WHERE
    pl.rideId = :rideId
ORDER BY
     pl.createdAt
DESC
LIMIT 1";

$stmt = $con->prepare($sql);
$stmt->execute([':rideId' => $rideId]);
$car_locations = $stmt->fetchAll(PDO::FETCH_ASSOC);

if ($car_locations) {
    // Print the car location data as JSON
    jsonSuccess($data = $car_locations);
} else {
    // Print a failure message
    jsonError($message = "No car locations found");
}

?>