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

$uid=$_GET['userid'];
$status=$_GET['status'];

if($status == 1){
    $resultdata =$con->query("select * from `request` where status='1' and userId='$uid' order by time desc");
}else{
$resultdata =$con->query("select * from `request` where status='2' or status='3' and userId='$uid' order by time desc");
}

$result=array();

   while($row=mysqli_fetch_array($resultdata))
    {
     //  
     $myAnimalId=$row['myAnimalId'];
     $animaltype=$row['animalType'];
      $userid=$row['userId'];
             $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'];
             
            }
    $userresult =$con->query("select * from `users`  where id='$userid'");
        
            while($rowuser=mysqli_fetch_array($userresult))
            {
            
                 $username=$rowuser['name'];
                 $userphone=$rowuser['phone'];
             
            }
  
  
  
  
  array_push($result,
      array(
            'id'=>$row['id'],
            'image'=>$image,
            'name'=>$animalname,
            'animaltype'=>$name,
            'gender'=>$row['gender'],
            'address'=>$row['address'],
            'description'=>$row['description'],
            'status' =>$row['status'],
            'age'=>$row['age'],
            'bookingType'=>$row['bookingType'],
            'latitude'=>$row['latitude'],
            'longitude'=>$row['longitude'],
            'userid'=>$row['userId'],
            'username' =>$username,
            'userphone' => $userphone    
          	));
    }

 echo json_encode(array("result"=>$result));

   
?>