dsnw2651 2018-08-25 11:01
浏览 32

如何从选项中获取所选元素的id

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'>  &nbsp;&nbsp;
         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.

  • 写回答

1条回答 默认 最新

  • dongrong6235 2018-08-25 11:21
    关注

    $eq1 & $eq2 should be assigned as below,

    $eq1=$_POST['code_olt'];
    $eq2=$_POST['code_fat'];
    
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致