<?php
require_once './includes/config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['member_id'])) {
    $memberId = $_POST['member_id'];

    $accounts = $pdo->prepare("
        SELECT ma.id AS account_id, at.account_name 
        FROM member_accounts ma
        JOIN account_types at ON ma.account_type_id = at.id
        WHERE ma.member_id = ?
    ");
    $accounts->execute([$memberId]);
    $accountList = $accounts->fetchAll(PDO::FETCH_ASSOC);

    $options = '<option value="all">All Accounts</option>';
    foreach ($accountList as $account) {
        $options .= "<option value='{$account['account_id']}'>{$account['account_name']}</option>";
    }

    echo $options;
}