prepare( "SELECT rental_date, end_date FROM bookings WHERE status IN ('pending','confirmed') AND rental_date <= ? AND end_date >= ?" ); $booked->execute([$end, $start]); $bookedDays = []; foreach ($booked->fetchAll() as $row) { $d = new DateTime($row['rental_date']); $e = new DateTime($row['end_date']); while ($d <= $e) { $bookedDays[] = $d->format('Y-m-d'); $d->modify('+1 day'); } } // Admin-blocked dates for this month $blocked = db()->prepare( "SELECT block_date FROM blocked_dates WHERE block_date BETWEEN ? AND ?" ); $blocked->execute([$start, $end]); foreach ($blocked->fetchAll() as $row) { $bookedDays[] = $row['block_date']; } echo json_encode([ 'month' => $month, 'year' => $year, 'booked_dates' => array_values(array_unique($bookedDays)), ]);