<?php
header('Content-Type: application/json');
require 'db.php'; // Include your database connection script

// Retrieve the user_id from the query string
$user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;

if ($user_id > 0) {
    // Fetch the latest trip status for the given user ID
    $sql = "SELECT status FROM new_trip_booking WHERE user_id = $user_id ORDER BY created_at DESC LIMIT 1";
    $result = $conn->query($sql);

    if ($result) {
        if ($result->num_rows > 0) {
            $row = $result->fetch_assoc();
            echo json_encode(['status' => $row['status']]);
        } else {
            echo json_encode(['status' => 'No trips found']);
        }
    } else {
        echo json_encode(['error' => 'Failed to execute query']);
    }
} else {
    echo json_encode(['error' => 'Invalid user ID']);
}

$conn->close();
?>
