<?php
include ('../includes/connection.php'); 

if (!empty($_POST["subject_id"])) {
    $subject_id = $_POST['subject_id'];
    $query = mysqli_query($conn, "SELECT * FROM module_soes WHERE status = 1 AND subject_id = '$subject_id'  ORDER BY code ASC");

    echo '<option value="">Select Module</option>';
    while ($row = mysqli_fetch_assoc($query)) {
        echo "<option value='{$row['module_id']}'>{$row['course_code']} | {$row['code']}</option>";
    }
}else{ 
        echo '<option value="">Module not available</option>'; 
} 

// if(isset($_POST["course_code"])){ 
//     // Fetch state data based on the specific country 
    
//     // $query_1= mysqli_query($conn,"SELECT * FROM subject_soes WHERE status = 1 AND subject_id = ".$_POST['course_code']."")or die(mysqli_error());
//     // $class1 = mysqli_fetch_array($query_1);
//     // $course_code=$class1['course_code'];
//     $query = "SELECT * FROM module_soes WHERE status = 1 AND course_code = ".$_POST['course_code']."  ORDER BY code ASC"; 
//     $result = $conn->query($query); 
     
//     // Generate HTML of state options list 
//     if($result->num_rows > 0){ 
//         echo '<option value="">Select Module</option>'; 
//         while($row = $result->fetch_assoc()){  
//             echo '<option value="'.$row['module_id'].'">'.$row['course_code'].' |'.$row['code'].'</option>'; 
//         } 
//     }else{ 
//         echo '<option value="">Module not available</option>'; 
//     } 
// }
?>