prepare("SELECT * FROM customer_applications WHERE id = ?"); $stmt->execute([$application_id]); $customer = $stmt->fetch(PDO::FETCH_ASSOC); if ($customer) { // Fetch contacts $stmt = $pdo->prepare("SELECT * FROM customer_contacts WHERE customer_application_id = ? ORDER BY is_primary DESC, id ASC"); $stmt->execute([$application_id]); $contacts = $stmt->fetchAll(PDO::FETCH_ASSOC); // Fetch addresses $stmt = $pdo->prepare("SELECT * FROM customer_addresses WHERE customer_application_id = ? ORDER BY id ASC"); $stmt->execute([$application_id]); $addresses = $stmt->fetchAll(PDO::FETCH_ASSOC); // Fetch files $stmt = $pdo->prepare("SELECT * FROM application_files WHERE customer_application_id = ? ORDER BY created_at DESC"); $stmt->execute([$application_id]); $files = $stmt->fetchAll(PDO::FETCH_ASSOC); } } catch (PDOException $e) { die("Database error: " . $e->getMessage()); } if (!$customer) { http_response_code(404); echo "Application not found."; exit(); } ?>