0
スクリプト必要があります。しばらく各映画のデータベースからPHP - データベースからのデータは変数と比較取得し、ソート小さい値によって
- テイク緯度及びlogitude()
- ユーザ の位置と比較
- は、それらのすべて
すべてがダウンし、以下のスクリプトで解決されて少ないキロに基づくすべて表示するキロ
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
私は昇順でそれらを表示する必要があります。
MySQLでこれを行う方法を示す多くの質問があります。しかし、あなたはPHPでそれをしたいですか? –
すべてを表示する前に、すべての値を配列に格納する必要があります。出力前にksortやソートなどの並べ替えコマンドがあります。 – Forbs
@RickJamesは私にmysqlのやり方を教えてください。 Forbsでコードを少し記述できますか –