So I have table "locations" (id,lat,lon,code of equipement), "fat"(code,name) and "olt"(code,name). I want to measure distance between "fat" and "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>
variables eq1 and eq2 should contain the code of each equipement
eq1 for olt and eq2 for fat.
and for the distance that's the code
$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>
this code calculate the distance but take the first option of olt and first option of fat.