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

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


$result=array();

   while($row=mysqli_fetch_array($resultdata))
    {
     $animalType=$row['animalType'];
      $userid=$row['userId'];
      $doctorId=$row['doctorId'];
    //   $address=$row['address'];
    //   $lat=$row['latitude'];
    //   $longitude=$row['longitude'];
      
   
$animalTypesql =$con->query("select * from `animal`  where id='$animalType'");
$animalname=null;
    while($rowanimalType=mysqli_fetch_array($animalTypesql))
    {
       
            $animalname = $rowanimalType['name'];
   
  
  
   
   
    }
    
    
    $doctorimagesarr=array();
    $doctorimages =$con->query("select * from `images`  where requestId='$requestid'");

    while($doctorimagesrow=mysqli_fetch_array($doctorimages))
    {
         array_push($doctorimagesarr,
        array(
            'id' => $doctorimagesrow['id'],
            'url' => $doctorimagesrow['url'],
    ));
    }
    
        $userresult =$con->query("select * from `users`  where id='$userid'");
        $username=null;
         $userphone=null;
            while($rowuser=mysqli_fetch_array($userresult))
            {
            $username=$rowuser['name'];
            $userphone=$rowuser['phone'];
            $memberShip=$rowuser['memberShip'];
             
            }
        $perceptionarr=array();
    $perception =$con->query("select * from `perception`  where requestid='$requestid' order by id desc");

    while($perceptionrow=mysqli_fetch_array($perception))
    {
         $perceptionarr[]=$perceptionrow;
    }     
     
     
    $doctorsresult =$con->query("select * from `doctors`  where id='$doctorId'");
        $partner=null;
         
            while($rowdoctors=mysqli_fetch_array($doctorsresult))
            {
            $partner=$rowdoctors['partner'];
            
            }       
     echo json_encode(array("result"=>$row,"animaltype"=>$animalname,"image"=>$doctorimagesarr,"username"=>$username,"userphone"=>$userphone,"memberShip"=>$memberShip,"partner"=>$partner,"perceptiondata"=>$perceptionarr));


}
   
?>