2016-01-01 78 views
1

我很难找到我的问题的解决方案。我写了一个应用程序,它以表单的形式请求地址,并通过PHP向MySQL数据库发送请求。这是APP的代码的摘录:mysql查询的错误订单

HttpPost httppost = new HttpPost("http://www.mywebsite.com/subfolder/selectall.php?PLAT=latitude_home&PLONG=longitude_home"); 

正如你可以看到我发送到PHP页面两个参数:纬度和经度这是两个double变量。

的PHP代码如下:

$R_latitude = $_REQUEST['PLAT']; 
$R_longitude = $_REQUEST['PLONG']; 

$latitude = floatval($R_latitude); 
$longitude = floatval($R_longitude); 

$con = mysql_connect(server,database,password); 
if (!$con) { 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("dbname", $con); 

$i=mysql_query("SELECT *,(((acos(sin((".$latitude."*pi()/180)) * sin((`Lat`*pi()/180))+cos((".$latitude."*pi()/180)) * cos((`Lat`*pi()/180)) * cos(((".$longitude."- `Lon`) * pi()/180))))*180/pi())*111.18957696) as distance FROM `Table` ORDER BY distance ASC LIMIT 10",$con); 

它应该我得到的结果,从兴趣点的距离的顺序,但我得到这个代码是顺序是错的,而如果我使用经度和纬度的固定值,一切都很好:

// $latitude = floatval($R_latitude); 
// $longitude = floatval($R_longitude); 
$latitude = 45.4283585; 
$longitude = 10.9669789; 

这里有什么问题?有人能够帮助吗? 非常感谢,新年快乐!

+0

使用库MySQLi不MySQL的。 – Script47

+1

请不要使用'mysql_'数据库扩展,它已被弃用(一去不复返在PHP7) 特别是如果你刚开始学习PHP,花你的精力学习'PDO'或'mysqli_'数据库扩展, [和这里一些帮助,以决定使用](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – RiggsFolly

+0

你有没有尝试在网址中插入一些固定值第一个代码片段? –

回答

-1

对不起球员......我做了一个非常愚蠢的错误...而不是

`HttpPost httppost = new HttpPost("http://www.mywebsite.com/subfolder/selectall.php?PLAT=latitude_home&PLONG=longitude_home");` 

我应该做的:

`HttpPost httppost = new HttpPost("http://www.mywebsite.com/subfolder/selectall.php?PLAT="+latitude_home+"&PLONG="+longitude_home+"");`