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

$userid=$_GET['userid'];


 $ssqqll="SELECT *  FROM request where  status='1' AND bookingType='consualt'  order by id desc";

$resultdata =$con->query($ssqqll);


$result=array();

   while($row=mysqli_fetch_array($resultdata))
    {
     $distance=$row['distance'];
     $myAnimalId=$row['myAnimalId'];
     $animaltype=$row['animalType'];
      $senderId=$row['userId'];
      
       $senderId=$row['userId'];
      
        $phone=null;
         $username=null;
         $userresult = $con->query("select * from `users` where id='$senderId'");
        
            while($rowuser=mysqli_fetch_array($userresult))
            {
        
             $phone=$rowuser['phone'];
              $username=$rowuser['name'];
            }
            
            
            
             $myAnimalresult =$con->query("select * from `myAnimal`  where id='$myAnimalId'");
        
            while($rowmyAnimal=mysqli_fetch_array($myAnimalresult))
            {
        
             $animalname=$rowmyAnimal['name'];
            }
   
   
            $animaltyperesult =$con->query("select * from `animal`  where id='$animaltype'");
        
            while($rowanimaltyperesult=mysqli_fetch_array($animaltyperesult))
            {
            
                 $name=$rowanimaltyperesult['name'];
                 $image=$rowanimaltyperesult['image'];
             
            }
    
  
  
  $kmdistance=$row['distance'] * 1.60934;
  
  array_push($result,
      array(
            'id'=>$row['id'],
            'userId'=>$row['userId'],
            'username'=>$username,
            'userphone'=>$phone,
            'image'=>$image,
            'name'=>$animalname,
            'animaltype'=>$name,
            'gender'=>$row['gender'],
            'address'=>$row['address'],
            'description'=>$row['description'],
            'status' =>$row['status'],
            'age'=>$row['age'],
            'latitude'=>$row['latitude'],
            'longitude'=>$row['longitude'],
             'distance'=>number_format($kmdistance ,2)
                
          	));
    }
 
 echo json_encode(array("result"=>$result));

   
?>