Hi I am trying to add a new feature to a website to find any results within a given readius. I found a script online that will calculate this for me but I am having trouble combining this with the current query. Can anyone see where I am going wrong?

Error returned by Mysql :
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 'Select * FROM form_data f inner join content c on f.content_id = c.id AND c.publ' at line 5

This is the original query which is working fine and uses a join to pull content from one table and location details from another including lat, lng etc

Select * FROM form_data f inner join content c on f.content_id = c.id AND c.published = "Y" AND c.trash != "Y"

And this is the query I am trying to modify:

    Select ID, Postcode, Lat, Lon, 
           acos(sin($lat)*sin(radians(Lat)) + cos($lat)*cos(radians(Lat))*cos(radians(Lon)-$lon))*$R As D
    From (
      Select ID, Postcode, Lat, Lon
      From MyTable
      Where Lat>$minLat And Lat<$maxLat
        And Lon>$minLon And Lon<$maxLon
      ) As FirstCut 
    Where acos(sin($lat)*sin(radians(Lat)) + cos($lat)*cos(radians(Lat))*cos(radians(Lon)-$lon))*$R < $rad
    Order by D";

This is how I tried to combine them:

Select * ,   
           acos(sin($lat)*sin(radians(lat)) + cos($lat)*cos(radians(lat))*cos(radians(lng)-$lon))*$R As D
    From (
      Select *
      FROM form_data f inner join content c on f.content_id = c.id AND published = 'Y' AND trash != 'Y'
      AND lat>$minLat And lat<$maxLat
        And lng>$minLon And lng<$maxLon
      ) As FirstCut 
     WHERE acos(sin($lat)*sin(radians(lat)) + cos($lat)*cos(radians(lat))*cos(radians(lng)-$lon))*$R < $miles 
    Order by D"
5 Years
Discussion Span
Last Post by Taywin

Could you try to use double quote in place of single quote? If it is inside a double quote already, use a backslash with double quote (\") to escape the double quote inside the existing double quote.

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.