<?php
include("../db.php");

if(isset($_POST['department_id'])){
    $department_id = mysqli_real_escape_string($con, $_POST['department_id']);

    // Fetch courses from `data` table where department_id (data_short_des) matches
    $course_sql = mysqli_query($con, "SELECT data_title, data_sl_no FROM data WHERE data_catagory = 'Course' AND data_subCategory = '$department_id' AND data_recycle = '1'");

    echo '<option value="">Select From List</option>';
    while($course_row = mysqli_fetch_assoc($course_sql)){
        $c_sql = mysqli_query($con, "SELECT * FROM  clg_course WHERE sl_no = '$course_row[data_title]'");
        if($c_row = mysqli_fetch_assoc($c_sql)){
            $c_name = $c_row["course_name"];
        }
        echo '<option value="'.$course_row['data_title'].'">'.$c_name.'</option>';
    }
}
?>