prepare("SELECT id FROM residents WHERE user_id = ?"); $stmt->execute([$_SESSION['user_id']]); $resident = $stmt->fetch(PDO::FETCH_ASSOC); if (!$resident) { // Handle case where resident profile is not found die("Resident profile not found."); } $resident_id = $resident['id']; // Basic Calendar Logic $month = isset($_GET['month']) ? (int)$_GET['month'] : date('m'); $year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y'); $today = date('Y-m-d'); $first_day_of_month = mktime(0, 0, 0, $month, 1, $year); $days_in_month = date('t', $first_day_of_month); $day_of_week = date('w', $first_day_of_month); // Fetch appointments for the month $stmt = $pdo->prepare("SELECT * FROM appointments WHERE resident_id = ? AND MONTH(start_time) = ? AND YEAR(start_time) = ? ORDER BY start_time"); $stmt->execute([$resident_id, $month, $year]); $appointments = []; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $day = date('j', strtotime($row['start_time'])); $appointments[$day][] = $row; } ?>