I make a service that give the nearby location of driver to passenger.
Is this query working? Is it actually search nearby location radius of passenger?
I just put the latitude and longitude a number.
Can you guys verify or explain to me?
SELECT b.id, b.name, b.latitude, b.longitude
FROM passenger a
JOIN driver b
ON ACOS(COS(RADIANS(a.latitude)) * COS(RADIANS(b.latitude)) * COS(RADIANS(b.longitude) - RADIANS(a.longitude)) + SIN(RADIANS(a.latitude)) * SIN(RADIANS(b.latitude))) <= 10 / 6371.0
WHERE a.latitude = 3.2046532 AND a.longitude = 101.7808791
<?php
error_reporting(E_ERROR | E_PARSE);
error_reporting(E_ALL);
ini_set('display_errors', '0');
include ("conn.php");
$latitude1 = 3.2046532;
$longitude1 = 101.7808791;
$stmt = $dbi->prepare("SELECT b.id, b.name, b.latitude, b.longitude
FROM passenger a
JOIN driver b
ON ACOS(COS(RADIANS(a.latitude)) * COS(RADIANS(b.latitude)) * COS(RADIANS(b.longitude) - RADIANS(a.longitude)) + SIN(RADIANS(a.latitude)) * SIN(RADIANS(b.latitude))) <= 10 / 6371.0
WHERE a.latitude = ? AND a.longitude = ?");
$stmt->bind_param('ss', $latitude1,$longitude1);
mysqli_stmt_execute($stmt) or die (mysqli_error());
mysqli_stmt_store_result($stmt) or die (mysqli_error());
mysqli_stmt_num_rows($stmt);
$stmt->bind_result($newID, $newName, $latitude2, $longitude2);
$stmt->fetch();
$stmt->close();
echo $newName.'<br>';
echo $latitude2.'<br>';
echo $longitude2.'<br>';
?>