<?php
if (isset($_POST['action'])) {
    include('conn_db.php');

    $output = '';

    if ($_POST["action"] == 'department') {
        echo "Hello, World";
        $query = "
		SELECT level FROM tbl_courses 
		WHERE department = :department 
		GROUP BY level
		";
        $statement = $connect->prepare($query);
        $statement->execute(
            array(
                ':department' => $_POST["query"]
            )
        );
        $result = $statement->fetchAll();
        $output .= '<option value="">Select Level</option>';
        foreach ($result as $row) {
            $output .= '<option value="' . $row["level"] . '">' . $row["level"] . '</option>';
        }
    }
    if ($_POST["action"] == 'level') {
        $query = "
		SELECT semester FROM tbl_courses 
		WHERE level = :level
		GROUP BY semester
		";
        $statement = $connect->prepare($query);
        $statement->execute(
            array(
                ':level' => $_POST["query"]
            )
        );
        $result = $statement->fetchAll();
        $output .= '<option value="">Select Semester</option>';
        foreach ($result as $row) {
            $output .= '<option value="' . $row["semester"] . '">' . $row["semester"] . '</option>';
        }
    }

    echo $output;
}

?>