<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
include '../../config/index.php';
$data = array();

$sql_d = "SELECT * FROM students WHERE center_id='" . $_GET["center_id"] . "' ORDER BY dated DESC";
$result_d = mysqli_query($conn, $sql_d);
if (mysqli_num_rows($result_d) > 0) {
    while ($row_d = mysqli_fetch_assoc($result_d)) {
        $class_name = "";
        $StreamName = "";
        $sql_clp = "SELECT * FROM centerClasses WHERE  centerClasses_id='" . $row_d['centerClasses_id'] . "'";
        $result_clp = mysqli_query($conn, $sql_clp);
        if (mysqli_num_rows($result_clp) > 0) {
            while ($row_clp = mysqli_fetch_assoc($result_clp)) {

                $sql_10 = "SELECT * FROM classes WHERE  class_id='" . $row_clp['class_id'] . "'";
                $result_10 = mysqli_query($conn, $sql_10);
                if (mysqli_num_rows($result_10) > 0) {
                    while ($row_10 = mysqli_fetch_assoc($result_10)) {
                        $class_name = $row_10["class_name"];
                    }
                }
                $sql_10 = "SELECT * FROM Streams WHERE  Streams_id='" . $row_clp['Streams_id'] . "'";
                $result_10 = mysqli_query($conn, $sql_10);
                if (mysqli_num_rows($result_10) > 0) {
                    while ($row_10 = mysqli_fetch_assoc($result_10)) {
                        $StreamName = $row_10["StreamName"];
                    }
                }
            }
        }
        $p_name = "";
        $p_last_name = "";
        $p_email = "";
        $p_phone = "";
        $p_image = "";
        $sql_10 = "SELECT * FROM parents WHERE  parent_id='" . $row_d['parent_id'] . "'";
        $result_10 = mysqli_query($conn, $sql_10);
        if (mysqli_num_rows($result_10) > 0) {
            while ($row_10 = mysqli_fetch_assoc($result_10)) {
                $p_name = $row_10["p_name"];
                $p_last_name = $row_10["p_last_name"];
                $p_email = $row_10["p_email"];
                $p_phone = $row_10["p_phone"];
                $p_image = $row_10["p_image"];
            }
        }


        $curl_post_data = array(
            'class_name' => $class_name,
            'p_name' => $p_name,
            'p_last_name' => $p_last_name,
            'p_email' => $p_email,
            'p_phone' => $p_phone,
            'p_image' => $p_image,
            'student_id' => $row_d["student_id"],
            'parent_id' => $row_d["parent_id"],
            'center_id' => $row_d["center_id"],
            'centerClasses_id' => $row_d["centerClasses_id"],
            'learner_name' => $row_d["learner_name"],
            'StreamName' => $StreamName,
            'learner_last_name' => $row_d["learner_last_name"],
            'learner_gender' => $row_d["learner_gender"],
            'learner_refugee' => $row_d["learner_refugee"],
            'disability_status' => $row_d["disability_status"],
            'learner_location' => $row_d["learner_location"],
            'learner_age' => $row_d["learner_age"],
            'learner_image' => $row_d["learner_image"],
            'status' => $row_d["status"],
            'homeschool' => $row_d["homeschool"],
            'username' => $row_d["username"],
            'password' => $row_d["password"],
            'reset' => $row_d["reset"],
        );
        array_push($data, $curl_post_data);
        $class_name = "";
        $StreamName = "";
        $p_name = "";
        $p_last_name = "";
        $p_email = "";
        $p_phone = "";
        $p_image = "";
    }
}



echo json_encode($data);
