<?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="SELECT * FROM centerMentors WHERE center_id='".$_GET["center_id"]."'  AND Deleted='false'";
    $result = mysqli_query($conn, $sql); 
    if (mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_assoc($result)) {
            $courses = array();  
            $mentor_name ; $mentor_email ; $mentor_phone ;
            $sql1="SELECT * FROM mentors WHERE mentor_id='".$row["mentor_id"]."' ";
            $result1 = mysqli_query($conn, $sql1); 
            if (mysqli_num_rows($result1) > 0) {
                while($row1 = mysqli_fetch_assoc($result1)) {
                    $mentor_name =  $row1["mentor_name"];
                    $mentor_email =  $row1["mentor_email"];
                    $mentor_phone =  $row1["mentor_phone"];
                }
            }

       
            $sql1="SELECT * FROM mentorCourse WHERE mentor_id='".$row["mentor_id"]."' AND center_id='".$row["center_id"]."' ";
            $result1 = mysqli_query($conn, $sql1); 
            if (mysqli_num_rows($result1) > 0) {
                while($row1 = mysqli_fetch_assoc($result1)) {
                    $sql10="SELECT * FROM courses WHERE course_id='".$row1["course_id"]."' ";
                    $result10 = mysqli_query($conn, $sql10); 
                    if (mysqli_num_rows($result10) > 0) {
                        while($row10 = mysqli_fetch_assoc($result10)) {
                            $curl_post_data = array(
                                'course_id' => $row1["course_id"],
                                'course_name' => $row10["course_name"],
                                'course_image' => $row10["Teachcourse_imageerFirstName"],
                            );
                          
                            array_push($courses, $curl_post_data);
                        }
                    }
                }
            }
            $curl_post_data = array(
                'centerMentors_id' => $row["centerMentors_id"],
                'center_id' => $row["center_id"],
                'mentor_id' => $row["mentor_id"],
                'mentor_name' => $mentor_name,
                'mentor_email' => $mentor_email,
                'mentor_phone' => $mentor_phone,
                'courses' => $courses,
            );
          
            array_push($data, $curl_post_data);
        }
    }
    echo json_encode($data);
 


?>