脚本应该:
所有内容都在下面的脚本中解决,只有4号没有实现。
我不知道如何比较while()循环的每个项目并按升序显示所有内容。
<?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>
}}
?>
脚本输出是:
20 km
movie information
5 km
movie information
45 km
movie information
1 km
movie information
我需要按升序显示它们。
答案 0 :(得分:0)
与您的距离使用sort()
。
echo sort($distance);