In PHP, how can a developer query the database to find available time ranges that do not overlap with existing entries?

When querying the database to find available time ranges that do not overlap with existing entries, the developer can use SQL queries to compare the start and end times of the existing entries with the desired time range. By selecting entries that do not overlap with the desired range, the developer can determine the available time slots.

// Assuming $start_time and $end_time are the desired time range
// $conn is the database connection

$sql = "SELECT * FROM table_name WHERE NOT (start_time >= '$end_time' OR end_time <= '$start_time')";
$result = mysqli_query($conn, $sql);

if(mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        // Process available time ranges
    }
} else {
    // No available time ranges found
}