<?php
header('Content-Type: application/json');

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "arnim";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    echo json_encode([]);
    exit;
}

$date = isset($_GET['date']) ? $conn->real_escape_string($_GET['date']) : '';

if($date != ''){
    $sql = "SELECT *
            FROM bookings 

            ORDER BY b.check_in ASC";

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

    $bookings = [];
    if($result->num_rows > 0){
        while($row = $result->fetch_assoc()){
            $bookings[] = $row;
        }
    }

    echo json_encode($bookings);
} else {
    echo json_encode([]);
}

$conn->close();
?>
