<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
// Replace these variables with your actual database credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ams";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// SQL query to fetch data from the 'delivery' table (replace 'delivery' with your actual table name)
$sql = "SELECT * FROM agents ORDER BY rand()";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $rows = array();

    // Fetch data and store in an array
    while ($row = $result->fetch_assoc()) {
        $rows[] = $row;
    }

    // Output the JSON-encoded array
    echo json_encode($rows);
} else {
    // Handle the case where no data is found
    echo json_encode(array());
}

$conn->close();
?>
