<?php

include 'includes/database.php';
include 'includes/functions.php';
$conn= new Functions();

if(!empty($_POST['districtID'])) {
    $districtID = $_POST['districtID'];


//fetch student's data based on the specific class
    $sql = "SELECT * FROM branches WHERE districtID =:districtID ORDER BY name";
    $conn->query($sql);
    $conn->bind(":districtID", $districtID);


//generate HTML of student option
    if ($conn->rowCount() > 0){
        $result = $conn->fetchMultiple();

        ?> <option value="">Select Section</option><?php
        foreach ($result as $branch) {
            $branch_name = $branch->name;
            ?> <option value="<?php echo $branch->id; ?>"><?php echo $branch_name; ?></option><?php
        }
    }else {
        echo "<option value=''> Branch Not Found </option>";
    }
}else {
    echo "<option value=''> Error Occured </option>";
}
