The current problem I have is I'm trying to output the data I am selecting but nothing seems to be returning, I tried the SQL separate and it seems to work, when I do echo "something" it will output it but not the foreach data
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
$get = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
$lat = $lon = $accuracy = "";
$userId = empty($_SESSION['userId']) ? 0 : $_SESSION['userId'];
$lat = $get['latitude'];
$lon = $get['longitude'];
$accuracy = $get['accuracy'];
$usersL = new UserLocations();
$results = $usersL->userslocations($lat, $lon, $accuracy, $userId);
foreach($results as $r){
echo $r['businessName'];
}
}
public function search($lat, $lon)
{
$db = new Database;
$query = "SELECT postcode, town, businessName, phone, street, lat, lon, distance
FROM (
SELECT z.postcode,
z.town,
z.businessName,
z.phone,
z.street,
z.lat, z.lon,
p.radius,
p.distance_unit
* DEGREES(ACOS(COS(RADIANS(p.latpoint))
* COS(RADIANS(z.lat))
* COS(RADIANS(p.longpoint - z.lon))
+ SIN(RADIANS(p.latpoint))
* SIN(RADIANS(z.lat)))) AS distance
FROM shopAddress AS z
JOIN (
SELECT :lat AS latpoint, :lon AS longpoint,
30.0 AS radius, 111.045 AS distance_unit
) AS p ON 1=1
WHERE z.lat
BETWEEN p.latpoint - (p.radius / p.distance_unit)
AND p.latpoint + (p.radius / p.distance_unit)
AND z.lon
BETWEEN p.longpoint - (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint))))
AND p.longpoint + (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint))))
) AS d
WHERE distance <= radius
ORDER BY distance
";
$stmt = $db->prepare($query);
$stmt->bindValue(':lat', $lat);
$stmt->bindValue(':lon', $lon);
$stmt->execute();
$results = $stmt->fetchAll();
return $results;
}
JS
$( document ).ready(function() {
$.get("save-geo.php", function(data){
$(".output-basic").append(data)
console.log('Data received: ', data);
});
});