Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7973837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:13:02+00:00 2026-06-04T08:13:02+00:00

Im trying to develop a small site which retrieves a results from a database

  • 0

Im trying to develop a small site which retrieves a results from a database by a set radius and places them on a map.
I use Google maps api to get the lat and long from there search criteria, pass these to my php script which queries the database and returns the result set as a JSON object.

Im having small a problem sending both the lat and long to the php using json.

My main problem is that my sql to search the database appears to be wrong as it just retrieves the first 10 results in my database. I want it to return the first 10 results within the radius from the search point.

Here is my ajax code

function showCarPark(location)
{
    var lat = location.lat();
    var lng = location.lng();
    //alert("Lat: " +lat.toFixed(6));
    //alert("Lng: " +lng.toFixed(6));
    document.getElementById('carParkResults').innerHTML = "";
    var criterion = document.getElementById("address").value;
    var count = 0;
    $.ajax({    
              url: 'process.php',
              type: 'GET',
              data: "lat=" + lat + "&lng=" + lng,
              dataType: 'json',
              success: function(data) 
              {
                  jQuery.each(data, function()
                  {
                    $('<p>').text("Car Park: " + data[count].name).appendTo('#carParkResults');
                    placeCarParks(data[count].postcode,data[count].name, data[count].street, data[count].type);
                    count++;
                  });
              },
              error: function(e) 
              {
                //called when there is an error
                console.log(e.message);
                alert("error" + e.message);
              }
    });

And here is my php script

$rad = 20;
$lat = $_GET['lat'];
$lng = 1.4681464; //put a temporary number in as it wont pass the lng in the JSON

$sql="SELECT *, (3959 * acos(cos(radians('".$lat."')) * cos(radians(lat)) * cos( radians(long) - radians('".$lng."')) + sin(radians('".$lat."')) * 
sin(radians(lat)))) 
AS distance 
FROM carpark HAVING distance < 15 ORDER BY distance LIMIT 0 , 10";

$result = mysql_query($sql);

while($r = mysql_fetch_assoc($result)) $rows[] = $r;

echo json_encode($rows);

The columns in my table are called lat and long
Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:13:03+00:00Added an answer on June 4, 2026 at 8:13 am

    For your case try to use WHERE instead of HAVING

    SELECT *, (3959 * acos(cos(radians('".$lat."')) * cos(radians(lat)) * cos( radians(long) - radians('".$lng."')) + sin(radians('".$lat."')) * 
    sin(radians(lat)))) 
    AS distance 
    FROM carpark WHERE distance < 15 ORDER BY distance LIMIT 0 , 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to develop a small section in my site, where I can
I am new to C# and trying to develop a small application which internally
I am trying to develop a small app BusTracker which will list down a
I'm trying to develop a scrollable tile map in Cocos2D which uses an UIPanGestureRecognizer
I'm trying develop a reddit style site which allows users to vote on links.
I'm trying to develop a small application that tests how many requests per second
I am trying to develop several small machine(such as a ic-m700pro ) simulator in
I'm trying to develop a small plugin that will do a sort-of auto-completion along
Small design question here. I'm trying to develop a calculation app in C#. I
I am trying to develop an XSLT stylesheet which will transform an xml into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.