<?php
// Connect to your MySQL database
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "sheeld";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}


$Trip_ID = $_GET['Trip_ID'];
$D_ID = $_GET['D_ID'];	




// Retrieve driver locations
$sql = "SELECT * FROM trips_users where Trip_ID='$Trip_ID' AND Driver_ID='$D_ID' AND Status!='Dropoff'";
$result = $conn->query($sql);
$locations = array();


if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
		
		
	$UT_ID=$row['ID'];
	$Trip_ID=$row['Trip_ID'];
	$User_ID=$row['User_ID'];
	$Gender=$row['Gender'];
	$Total_Riders=$row['Total_Riders'];
	$From_Longitude=$row['From_Longitude'];
	$From_Latitude=$row['From_Latitude'];
	$To_Longitude=$row['To_Longitude'];
	$To_Latitude=$row['To_Latitude'];
	$From_Location=$row['From_Location'];
	$To_Location=$row['To_Location'];
	$Total_Price_All_Riders=$row['Total_Price_All_Riders'];
	$Payment_Type=$row['Payment_Type'];
	$User_Rate_Status=$row['User_Rate_Status'];
	$Status=$row['Status'];
	$Spot_Number=$row['Spot_Number'];
	
		
	$sql1 = "SELECT * FROM users where ID='$User_ID'";
	$result1 = $conn->query($sql1);	
	$row1 = $result1->fetch_assoc();	
		
	$UID=$row1['ID'];
	$UName=$row1['Name'];
	$UPhone_Number=$row1['Phone_Number'];
	$UPhoto=$row1['Photo'];
	$UGender=$row1['Gender'];
	
		
		
		
	$sql2 = "SELECT * FROM trip_spots where Trip_ID='$Trip_ID' AND Spot_Number='$Spot_Number'";
	$result2 = $conn->query($sql2);
    $row2 = $result2->fetch_assoc(); 
	
	$Spot_Longitude = $row2['Longitude'];
	$Spot_Latitude = $row2['Latitude'];



	
	













	
		



$arr = array('Trip_ID' => $Trip_ID);
$arr1 = array('UT_ID' => $UT_ID);
$arr2 = array('Gender' => $Gender);
$arr3 = array('UID' => $UID);
$arr4 = array('UName' => $UName);
$arr5 = array('UPhone_Number' => $UPhone_Number);
$arr6 = array('Spot_Longitude' => $Spot_Longitude);
$arr7 = array('Spot_Latitude' => $Spot_Latitude);
$arr8 = array('Total_Riders' => $Total_Riders);
$arr9 = array('From_Longitude' => $From_Longitude);
$arr10 = array('From_Latitude' => $From_Latitude);
$arr11 = array('To_Longitude' => $To_Longitude);
$arr12 = array('To_Latitude' => $To_Latitude);
$arr13 = array('From_Location' => $From_Location);
$arr14 = array('To_Location' => $To_Location);
$arr15 = array('User_Rate_Status' => $User_Rate_Status);
$arr16 = array('Total_Price_All_Riders' => $Total_Price_All_Riders);
$arr17 = array('Payment_Type' => $Payment_Type);
$arr18 = array('Spot_Number' => $Spot_Number);
$arr19 = array('Status' => $Status);
$arr20 = array('Spot_Longitude' => $Spot_Longitude);
$arr21 = array('Spot_Latitude' => $Spot_Latitude);
$arr22 = array('UGender' => $UGender);
$arr23 = array('UPhoto' => $UPhoto);


$locations[] = $row+$arr+$arr1+$arr2+$arr3+$arr4+$arr5+$arr6+$arr7+$arr8+$arr9+$arr10+$arr11+$arr12+$arr13+$arr14+$arr15+$arr16+$arr17+$arr18+$arr19+$arr20+$arr21+$arr22+$arr23;

	
		
		
	}
		
		
		
		
    }else{
		
		
		
	}


$conn->close();

header("Content-Type: application/json");



echo json_encode($locations);


	  
?>