57208

Question:
Script should:
<ol><li>Take latitude and logitude from database of each cinema with while()</li> <li>Compare to location of a user</li> <li>Get the output in kilometers</li> <li>Show all of them based on less kilometers</li> </ol>Everything is solved on the script down below, only number 4 is not implemented.
I have no idea how to compare every item of while() loop and show everything in the ascending order.
<?php
$sql = "SELECT DISTINCT * FROM cinemas WHERE city='$city'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$lat1 = $_GET['lat']; //latitude of a user
$lon1= $_GET['lon']; //longitude of a user
$lat2 = $row['latitude']; //latitude of a cinema
$lon2 = $row['longitude']; //longitude of a cinema
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = $miles * 1.609344; //calculated the distance between them
$distance = substr($unit,0,4)." km"; //output of a distance
echo $distance;
?>
//here is the data about movie
<div id="time"><?php echo $row3['showone']; // timing of a movie ?></div>
}}
?>
Script out is:
20 km
movie information
5 km
movie information
45 km
movie information
1 km
movie information
I need to show them in ascending order.
Answer1:Use sort()
with your distance.
echo sort($distance);