calculate distance between 2 points using php and mysql -


i have form allow user select database city 's name fro first point , city's name second point submit calculate button

the village table contain:

  • id
  • village_name
  • longitude
  • lattitude
  • district_id

i did in code not show , var_dump show null

can me ?????

map.php

    <?php          if(isset($_post['calculate']))         {             $pt1 = $_post['pt1'];             $pt2 = $_post['pt2'];              $sql = mysql_query("select longitude, lattitude village id = '$pt1' , id = '$pt2'")or die(mysql_error());             $num_row = mysql_num_rows($sql);             if($num_row > 0)             {                 while($row = mysql_fetch_array($sql))                 {                     $lon_s = $row['longitude'];                     $lon_e = $row['longitude'];                     $lat_s = $row['lattitude'];                     $lat_e = $row['lattitude'];                      var_dump($lon_e);                     var_dump($lon_s);                     var_dump($lat_e);                     var_dump($lat_s);                      $r = 6371; //km                     $a = pow(sin(($lat_e - $lat_s)/2), 2) + cos($lat_s) * cos($lat_e) * pow(sin(($lon_e - $lon_s)/2) , 2);                     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));                     $d = $r * $c;             echo $d;                  }             }         } 

html code

<table width="30%" border="3" align="right">                 <form action="map.php" method="post">                   <tr>                     <td width="37%"> location one: </td>                     <td width="63%"><select id="location1" name="pt1">                       <?php echo $opt->showlocation() ?>                       </select>                       <br /></td>                   </tr>                   <tr>                     <td>location two:</td>                     <td><select id="location2" name="pt2">                       <option value="0">choose...</option>                       </select></td>                   </tr>                   <tr>                     <td>&nbsp;</td>                     <td><input type="submit" name="calculate" value="calculate distance" /></td>                   </tr>                 </form>               </table> 

it's because where id = '$pt1' , id = '$pt2'

you should have 1 on where clause

where id = '$pt1' 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -