<?php
include '../../conn.php';

$doctorid=$_GET['doctorid'];
$resultdata =$con->query("select * from `doctors` where id='$doctorid'");


$result=array();

   while($row=mysqli_fetch_array($resultdata))
    {
     $id=$row['id'];
     
     $doctorspecial =$con->query("select * from `doctorServices`  where doctorId='$id'");
   
    $veterinarySpecialtiesarr=array();
    while($rowdoctorspecial=mysqli_fetch_array($doctorspecial))
    {

     $idsp=$rowdoctorspecial['specialtiesId'];
    
    $veterinarySpecialties =$con->query("select * from `veterinarySpecialties`  where id='$idsp'");

    while($rowveterinarySpecialties=mysqli_fetch_array($veterinarySpecialties))
    {
         array_push($veterinarySpecialtiesarr,
        array(
            'id' => $rowveterinarySpecialties['id'],
            'name' => $rowveterinarySpecialties['name'],
    ));
  
  
   
    }
    }
    
    
    $doctorimagesarr=array();
    $doctorimages =$con->query("select * from `images`  where doctorId='$ids' order by id desc");

    while($doctorimagesrow=mysqli_fetch_array($doctorimages))
    {
         array_push($doctorimagesarr,
        array(
            'id' => $doctorimagesrow['id'],
            'url' => $doctorimagesrow['url'],
    ));
    }
    
       $review=array();
   $feedbackresultdata =$con->query("select * from `feedback` where doctorId=$doctorid order by id desc");
   while($feedbackrow=mysqli_fetch_array($feedbackresultdata))
    {
     
        $userid=$feedbackrow['userId'];
         $message=$feedbackrow['message'];
        $usersresultdata =$con->query("select * from `users` where id=$userid ");
   while($usersrow=mysqli_fetch_array($usersresultdata))
    {
         array_push($review,
        array(
            'image' => $usersrow['image'],
            'name' => $usersrow['name'],
            'review'=>$message
    ));
       // $review[]=$usersrow;
    }
    }  
    
     echo json_encode(array("result"=>$row,"services"=>$veterinarySpecialtiesarr,"images"=>$doctorimagesarr,"review"=>$review));


}
   
?>