所以我有表格“位置”(id,lat,lon,设备代码), “ fat”(代码,名称)和“ olt”(代码,名称)。 我想测量“脂肪”和“脂肪”之间的距离。
if($_GET['type'] == "olt_fat"){?>
<div class='div2'>
Remplir ce formulaire : </div><br>
<form action="" method="Post">
Entre le olt : <SELECT name="code_olt" size="1">
<?php
$run = mysql_query("SELECT * from eq,olt where type ='C' and olt.code=eq.code");
while($row = mysql_fetch_assoc($run)){
$ss[] = array(
'code' => $row['code'],
'name' => $row['name'],
'capa_max_fat' => $row['capa_max_fat'],
'capa_max_olt' => $row['capa_max_olt'],
);
}
foreach ($ss as $key => $value) {
echo ' <OPTION value="'.$value['code'].'" >'.$value['code'].'/'.$value['name'].' </OPTION>';
}
$eq1=$_POST['code'];
?>
</SELECT><br><br>
et le fat : <SELECT name="code_fat" size="1">
<?php
$run = mysql_query("SELECT * from eq,fat where type ='A' and fat.code=eq.code");
while($row = mysql_fetch_assoc($run)){
$mm[] = array(
'code' => $row['code'],
'name' => $row['name'],
);
}
foreach ($mm as $key => $value) {
echo ' <OPTION value="'.$value['code'].'" >'.$value['code'].'/'.$value['name'].' </OPTION>';
}
$eq2=$_POST['code'];
?>
</SELECT>
<input type="submit" value="mesurer" name="calcul"><br><br>
变量eq1和eq2应包含每个设备的代码
eq1代表olt,eq2代表脂肪。
而距离就是代码
$sql = "SELECT lat FROM `locations` WHERE description='".$eq1."'";
$lat1 = mysql_query($sql);
$sql1 = "SELECT lon FROM `locations` WHERE description='".$eq1."'";
$lon1 = mysql_query($sql1);
$sql2 = "SELECT lat FROM `locations` WHERE description='".$eq2."'";
$lat2 = mysql_query($sql2);
$sql3 = "SELECT lon FROM `locations` WHERE description='".$eq2."'";
$lon2 = mysql_query($sql3);
$latitudeFrom = $lat1;
$longitudeFrom = $lon1;
$latitudeTo = $lat2;
$longitudeTo = $lon2;
//Calculate distance from latitude and longitude
$theta = $longitudeFrom - $longitudeTo;
$dist = sin($rad = ($latitudeFrom * M_PI / 180)) * sin($rad = ($latitudeTo *
M_PI / 180)) + cos($rad = ($latitudeFrom * M_PI / 180)) * cos($rad =
($latitudeTo * M_PI / 180)) * cos($rad = ($theta * M_PI / 180));
$dist = ($rad=($dist * M_PI / 180));
$distance = ($dist * 1.609344).' km';?>
Distance(m) : <input type="text" value =""> <?php echo $distance; } ?>
<br><br>
<input type="submit" value="ajouter" name="ajouter"><br><br>
</form><br>
</div>
此代码计算距离,但采用olt的第一选项和fat的第一选项。
答案 0 :(得分:0)
$ eq1&$ eq2应按以下方式分配,
$eq1=$_POST['code_olt'];
$eq2=$_POST['code_fat'];