2
Good evening, I need a help with the code below.
This code already works for what I need. Geolocation to display the nearest users, but how I get the distance value???
$user = $con->query("SELECT user_nome, user_user, user_idade, user_img,
(6371 * acos(
cos( radians($lat) )
* cos( radians( user_latitude ) )
* cos( radians( user_longitude ) - radians($long) )
+ sin( radians($lat) )
* sin( radians( user_latitude ) )
)
) AS distancia
FROM usuarios
HAVING distancia < 400
ORDER BY distancia ASC LIMIT 50", PDO::FETCH_ASSOC);
That distance is neither in my bank nor in variable. I wanted to show for example in a table: user_name and distance
Thank you
By doing what you’re doing, the field
distancia
is automatically created in the associative array that has the results of your query. Just iterate using a foreach, for example:foreach ($user as $row) { echo $row['distancia'] }
.– João Pedro Henrique