1

我有一个表格,允许用户从数据库中选择第一点的城市名称,然后选择第二点的城市名称,然后提交计算按钮

村庄表包含:

  • ID
  • 村名
  • 经度
  • 纬度
  • 区号

我在我的代码中这样做了,但它没有显示任何内容,并且var_dump显示为 null

谁能帮我 ?????

地图.php

    <?php 
        if(isset($_POST['calculate']))
        {
            $pt1 = $_POST['pt1'];
            $pt2 = $_POST['pt2'];

            $sql = mysql_query("SELECT longitude, lattitude FROM village WHERE id = '$pt1' AND 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 代码

<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>
4

1 回答 1

1

这是因为WHERE id = '$pt1' AND id = '$pt2'

你应该有 1WHERE clause

WHERE id = '$pt1'
于 2013-05-14T08:12:22.563 回答