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

$doctorid=$_GET['userId'];
$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))
    {
     $doctorServices= $rowdoctorspecial['id'];
     $idsp=$rowdoctorspecial['specialtiesId'];
    
    $veterinarySpecialties =$con->query("select * from `veterinarySpecialties`  where id='$idsp' order by id desc");

    while($rowveterinarySpecialties=mysqli_fetch_array($veterinarySpecialties))
    {
         array_push($veterinarySpecialtiesarr,
        array(
            'id' => $doctorServices,
            'name' => $rowveterinarySpecialties['name'],
    ));
  
  
   
    }
    }
    
    
    $doctorimagesarr=array();
    $doctorimages =$con->query("select * from `images`  where doctorId='$id' 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;
    }
    }  
    /////////////////all service/////////////
   
    $allveterinarySpecialties =$con->query("select * from `veterinarySpecialties` order by name asc");
   $allveterinarySpecialtiesarr=array();
    while($allrowveterinarySpecialties=mysqli_fetch_array($allveterinarySpecialties))
    {
        $allveterinarySpecialtiesarr[]=$allrowveterinarySpecialties;
    }
  
  
     echo json_encode(array("result"=>$row,"services"=>$veterinarySpecialtiesarr,"images"=>$doctorimagesarr,"review"=>$review,"allservice"=>$allveterinarySpecialtiesarr));


}
   
?>