dou4121 2012-09-23 23:56
浏览 55
已采纳

SQL Query在PHPMyAdmin中运行良好,但在mysql_query中运行不正常

The following SQL query works perfectly fine when I run it with PHPMyAdmin but when I run it from a web page I get an error. I have looked around on StackOverflow for similar questions and have tried their suggestions but alas... Does anyone have an idea why it won't work on the web page?

The SQL query after variables have been put in (example):

SELECT place FROM locations WHERE (( 69.1 * ( latitude - 51.4700000 ) ) * ( 69.1 * (latitude - 51.4700000 ) )) + ( ( 69.1 * ( longitude - 5.5528000 ) * COS( 51.4700000 / 57.3 )) * ( 69.1 * ( longitude - 5.5528000 ) * COS( 51.4700000 / 57.3 ) ) ) < 976.5625 ORDER BY ((69.1 * ( latitude - 51.4700000 ) ) * ( 69.1 * ( latitude - 51.4700000 ) )) + ( ( 69.1 * ( longitude - 5.5528000 ) * COS( 51.4700000 / 57.3 ) ) * ( 69.1 * ( longitude - 5.5528000 ) * COS(51.4700000 / 57.3 ) ) ) ASC

The PHP ($radius and $start are defined a little before this):

$latitude = $start['latitude'];
$longitude = $start['longitude'];
$r = pow($radius, 2);
$inrange = "SELECT place FROM locations_2 WHERE ((69.1 * (latitude - $latitude)) * (69.1 * (latitude - $latitude))) + ((69.1 * (longitude - $longitude) * COS($latitude / 57.3)) * (69.1 * (longitude - $longitude) * COS($latitude / 57.3))) < $r ORDER BY ((69.1 * (latitude - $latitude)) * (69.1 * (latitude - $latitude))) + ((69.1 * (longitude - $longitude) * COS($latitude / 57.3)) * (69.1 * (longitude - $longitude) * COS($latitude / 57.3))) ASC";
$result = mysql_query($inrange) or die(mysql_error());

The error message I get is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) * (69.1 * (`latitude` - ))) + ((69.1 * (`longitude` - ) * COS( / 57.3)) * (69' at line 1

What's even stranger is that it worked... I wrote it all down, just the way I'm presenting it to you now, and was happy to see it worked just fine. That was earlier today. Now an hour or so ago I tried it again and for some reason it stopped working. I truly don't remember changing a thing.

EDIT

Thanks everyone. I figured it out and it turned out I made a stupid mistake. It worked earlier today because all the users had their location set. Now, I have a few users that don't so while looping through them the longitude and latitude came up empty.

  • 写回答

2条回答 默认 最新

  • douxi9245 2012-09-23 23:59
    关注

    From your error message it seems like $latitude and $longitude does not contain any values. You probably want to check that $start is properly set. This is all I can help you with since I do not know what $start is and how you're getting it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?