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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:22:00+00:00 2026-05-20T08:22:00+00:00

I have found many calculations here and some php examples and most are just

  • 0

I have found many calculations here and some php examples and most are just over my head.

I found this example:

SELECT b.zip_code, b.state,
       (3956 * (2 * ASIN(SQRT(
       POWER(SIN(((a.lat-b.lat)*0.017453293)/2),2) +
       COS(a.lat*0.017453293) *
       COS(b.lat*0.017453293) *
       POWER(SIN(((a.lng-b.lng)*0.017453293)/2),2))))) AS distance
FROM zips a, zips b
WHERE
       a.zip_code = '90210' ## I would use the users submitted value
GROUP BY distance
having distance <= 5; ## I would use the users submitted value

But, I am having trouble understanding how to implement the query with my database.

It looks like that query has all I need.

However, I cannot even find/understand what b.zip_code actually is! (whats the b. and zips a, zips b?)

I also do not need the state in the query.

My mySQL db structure is like this:

    ZIP | LAT     | LONG
  33416 | 26.6654 | -80.0929

I wrote this in attempt to return some kind of results (not based on above query) but, it only kicks out one zip code.

## Just for a test BUT, in reality I desire to SELECT a zip code WHERE ZIP = the users submitted zip code
## not by a submitted lat lon. I left off the $connect var, assume it's there.
my $set1 = (26.6654 - 0.20);
my $set2 = (26.6654 + 0.20);
my $set3 = (-80.0929 - 0.143);
my $set4 = (-80.0929 + 0.143);
my $test123 = $connect->prepare(qq{SELECT `ZIP` FROM `POSTAL`
WHERE `LAT` >= ? AND `LAT` <= ? 
AND `LONG` >= ? AND `LONG` <= ?})  or die "$DBI::errstr";
$test123->execute("$set1","$set2","$set3","$set4") or die "$DBI::errstr";
my $cntr;
while(@zip = $test123->fetchrow_array()) {
    print qq~$zip[$cntr]~;
    push(@zips,$zip[$cntr]);
    $cntr++;
}

As you can see, I am quite the novice so, I need some hand holding here with verbose explanation.

So, in Perl, how can I push zip codes into an array from a USER SUBMITTED ZIP CODE and user submitted DISTANCE in miles. Can be a square instead of a circle, not really that critical of a feature. Faster is better.

  • 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-20T08:22:01+00:00Added an answer on May 20, 2026 at 8:22 am

    I don’t see what’s wrong with your first query. You have latitude and longitude in your database (if I’m understanding, you’re comparing a single entry to all others). You don’t need to submit or return the state that’s just part of the example. Make the first query work like this:

    my $query = "SELECT b.zip_code,
           (3956 * (2 * ASIN(SQRT(
           POWER(SIN(((a.lat-b.lat)*0.017453293)/2),2) +
           COS(a.lat*0.017453293) *
           COS(b.lat*0.017453293) *
           POWER(SIN(((a.lng-b.lng)*0.017453293)/2),2))))) AS distance
    FROM zips a, zips b WHERE
           a.zip_code = ? 
    GROUP BY distance having distance <= ?";
    
    my $sth = $dbh->prepare($query);
    $sth->execute( $user_submitted_zip, $user_submitted_distance );
    while( my ($zip, $distance) = $sth->fetchrow() ) ) {
         # do something
    }
    

    This won’t be that fast, but if you have a small record set ( less than 30k rows ) it should be fine. If you really want to go faster you should look into a search engine such as Sphinx which will do this for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found some similar questions like this one, however there are so many
I have found many sites that describes PRG, but no simple PHP code example.
This is something I've pseudo-solved many times and have never quite found a solution
I have found some libraries or web services in PHP that does the job.
In many code examples I have found the DisplayRectangle property of a Control object
I have found this example on StackOverflow: var people = new List<Person> { new
I have searched this site for an answer and found many responses to unsigned/signed
I have found many references to this term on the web, especially on Microsoft's
I have found that writing PHP code within classes can become rather long: $this->parser->parse_syntax($this->get_language_path($this->language),
I have found this line in a php book is it right? I do

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.