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

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

    $product_sql = mysqli_query($con, "SELECT * FROM product WHERE pid = '$course_id' ");
    if($product_row = mysqli_fetch_assoc($product_sql)){
        $course_id = $product_row["product"];
    }

    $query = "SELECT * FROM branch WHERE b_class = '$course_id' AND b_recycle = '1' ORDER BY batch_title ASC";
    $result = mysqli_query($con, $query);

    echo '<option value="">Select Batch</option>';

    if (mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
            echo '<option value="' . htmlspecialchars($row['b_id']) . '">' . htmlspecialchars($row['batch_title']) . '</option>';
        }
    } else {
        echo '<option value="">No Batch Available</option>';
    }
}
?>