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条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法