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 3962846
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:08:41+00:00 2026-05-20T03:08:41+00:00

So I have a MySQL database with cities/counties within the United States with longitude

  • 0

So I have a MySQL database with cities/counties within the United States with longitude and latitude.

This is the query we are using to get results within 10 miles on any position for this example.

SELECT city, state,((ACOS(SIN('38.2966016' * PI() / 180) * SIN(lat * PI() / 180) + COS('38.2966016' * PI() / 180) * COS(lat * PI() / 180) * COS(('-77.634079'-lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance FROM zcta HAVING distance <= '10' ORDER BY distance ASC

When testing in Sequel Pro results come back as expected:

Fredericksburg      VA  4.5932632328546
Spotsylvania        VA  6.1939678870939
Richardsville       VA  6.8293644913069
Locust Grove        VA  7.6479616882979
Hartwood            VA  7.6509448009002
Fredericksburg      VA  7.8178182509761
Fredericksburg      VA  7.8328645163604
Fredericksburg      VA  7.8499527233007
Fredericksburg      VA  7.8832043684573
Fredericksburg      VA  8.8620101042208

However when plugged into the following Zend Framework:

    $db = $this->getAdapter();
    $sql = "SELECT city, state,((ACOS(SIN('38.2965709' * PI() / 180) * SIN(lat * PI() / 180) + COS('38.2965709' * PI() / 180) * COS(lat * PI() / 180) * COS(('-77.6340366'-lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance` FROM `zcta` HAVING `distance`<='10' ORDER BY `distance` ASC";
    //$sql = "SELECT city, state,((ACOS(SIN('".$lat."' * PI() / 180) * SIN(lat * PI() / 180) + COS('".$lat."' * PI() / 180) * COS(lat * PI() / 180) * COS(('".$lon."'-lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance` FROM `zcta` HAVING `distance`<='10' ORDER BY `distance` ASC";
    $stmt = $db->query($sql);
    $rows = $stmt->fetchAll();
    return $rows;

We get results (Order by closes)

Champlain, VA
Hustle, VA
Caret, VA
Tappahannock, VA
Loretto, VA

Champlain, VA is over 39 miles away. It’s the same query, I even tested it within shell and got the same results as the Sequel Pro Fredericksburg results. Because of this I’m assuming Zend Framework is changing something when querying the database, thus the Champlain, VA results.

I am a newbie to ZF so is there something I’m missing to get ZF to return the results correctly?

  • 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-05-20T03:08:42+00:00Added an answer on May 20, 2026 at 3:08 am

    Never heard of this problem. Have you tried to remove any quotes from Integers/Floats of your query:

    $sql = "SELECT city, state,((ACOS(SIN(38.2965709 * PI() / 180) * SIN(lat * PI() / 180) + COS(38.2965709 * PI() / 180) * COS(lat * PI() / 180) * COS((-77.6340366-lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance` FROM `zcta` HAVING `distance`<=10 ORDER BY `distance` ASC";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following mysql database tables: cities states countries with members samajs (a group
I have three tables in a Mysql database - countries, cities and hotels. Their
I have mysql database like this id | code 1 | bok-1 2 |
I have a MySQL database table called Participant that looks something like this: (idParticipant)
I have a MySQL database with a date_of_birth field. The data stored in this
I have database of different hotels for different cities. Each hotel has latitude and
I'm using the following mysql query to return some data from my database. Currently
I have mysql database and I want to get the last ID from field
I have mysql database and I want a software which can draw the database
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT

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.