<?php
include 'db.php'; // Include database connection

if (isset($_GET['category_id'])) {
    $category_id = $_GET['category_id'];

    // Fetch topics for the selected category
    $stmt = $pdo->prepare("SELECT id, name FROM topics WHERE category_id = :category_id ORDER BY name");
    $stmt->bindParam(':category_id', $category_id, PDO::PARAM_INT);
    $stmt->execute();

    $topics = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo '<option value="">Choose Topic</option>';
    foreach ($topics as $topic) {
        echo '<option value="' . $topic['id'] . '">' . $topic['name'] . '</option>';
    }
}
?>
