query("SELECT * FROM donors WHERE status = 'approved'")->fetchAll(PDO::FETCH_ASSOC); $recipients = $pdo->query("SELECT * FROM recipients")->fetchAll(PDO::FETCH_ASSOC); $matches_found = 0; foreach ($recipients as $recipient) { foreach ($donors as $donor) { // Simple matching logic: blood type and organ must match // And donor must have the organ listed if ($recipient['blood_type'] === $donor['blood_type'] && strpos($donor['organs'], $recipient['organ']) !== false) { // Check if this match already exists $stmt = $pdo->prepare("SELECT id FROM matches WHERE donor_id = ? AND recipient_id = ?"); $stmt->execute([$donor['id'], $recipient['id']]); if (!$stmt->fetch()) { // Insert new match as 'pending' $insert_stmt = $pdo->prepare("INSERT INTO matches (donor_id, recipient_id, status) VALUES (?, ?, 'pending')"); $insert_stmt->execute([$donor['id'], $recipient['id']]); $matches_found++; } } } } if ($matches_found > 0) { $match_message = "Found $matches_found new potential matches! They are now pending approval."; } else { $match_message = "No new matches found at this time."; } } catch (PDOException $e) { $match_message = "Database error during matching: " . $e->getMessage(); } } // Fetch current matches $matches = $pdo->query(" SELECT m.id, d.name as donor_name, r.name as recipient_name, h.name as hospital_name, m.status FROM matches m JOIN donors d ON m.donor_id = d.id JOIN recipients r ON m.recipient_id = r.id JOIN hospitals h ON r.hospital_id = h.id ORDER BY m.created_at DESC ")->fetchAll(PDO::FETCH_ASSOC); ?> <?= htmlspecialchars($page_title) ?> - Organ Donation

Organ Donation Management

Run Matching Algorithm

Click the button below to find potential matches between approved donors and recipients.


Current Matches

No matches found yet.

Donor Recipient Hospital Status Action