<?php
require 'dbconn.php'; // Make sure $mysqli is available

// Fetch Presidents
$presidents = [];
$res = $mysqli->query("SELECT * FROM presidents");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $presidents[] = $row;
    }
}

// Fetch Vice Presidents
$vice_presidents = [];
$res = $mysqli->query("SELECT * FROM vice_presidents");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $vice_presidents[] = $row;
    }
}

// Fetch Secretaries
$secretaries = [];
$res = $mysqli->query("SELECT * FROM secretory");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $secretaries[] = $row;
    }
}

// Fetch Joint Secretaries
$joint_secretaries = [];
$res = $mysqli->query("SELECT * FROM joint_secretory");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $joint_secretaries[] = $row;
    }
}

// Fetch Treasurers
$treasurers = [];
$res = $mysqli->query("SELECT * FROM treasurer");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $treasurers[] = $row;
    }
}

// Fetch Committee Members
$committee_members = [];
$res = $mysqli->query("SELECT * FROM commitee_members");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $committee_members[] = $row;
    }
}


// Fetch News 
$news = [];
$res = $mysqli->query("SELECT * FROM news_tb");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $news[] = $row;
    }
}


// Fetch Events
$events = [];
$res = $mysqli->query("SELECT * FROM events_tb");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $events[] = $row;
    }
}
// Fetch category
$catagory = [];
$res = $mysqli->query("SELECT * FROM project_tb");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $catagory[] = $row;
    }
}
// Fetch Images
$images = [];
$res = $mysqli->query("SELECT * FROM project_pictures");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $images[] = $row;
    }
}

// Fetch Videos
$videos = [];
$res = $mysqli->query("SELECT * FROM videos");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $videos[] = $row;
    }
}
// Fetch Circular
$circular = [];
$res = $mysqli->query("SELECT * FROM circulars_tb");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $circular[] = $row;
    }
}
// Fetch Members
$members = [];
$res = $mysqli->query("SELECT * FROM members");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $members[] = $row;
    }
}

// Get ID from query string for family member lookup
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
// Fetch family Members
$F_members = [];
$res = $mysqli->query("SELECT * FROM family_members WHERE member_id='$id'");
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        $F_members[] = $row;
    }
}
?>