Click here to Skip to main content
12,552,516 members (28,736 online)
Rate this:
Please Sign up or sign in to vote.
See more: PHP MySQL
I have 2 tables 1st with post code and category and second with postcodes, latitude and longitude. Now i want to search ... hear is table format before i move to my question
**Table1 (uk_data)** 
 **comp_post_code**   cat1  **cat2**
**Table2 (uk_pc)** 
 **Postcode**   Latitude  **Longitude**

Now I want to search cat1 and cat2 by cost code ... which i have made it is
SELECT * from uk_data where
cat10 like :comp_post_code  AND (
cat1 like :cat OR
cat2 like :cat)
This gives me result which is on this post code but Now i want to search items where are with in 5 mines and 10 miles of area how can i do that ?
I know how to calculate distance between postcodes but here is the code
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);
  if ($unit == "K") {
    return ($miles * 1.609344);
  } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
But dont know how can i get this in loop to chick Table 2 for get result in 5 or 10 miles ... please help
Posted 29-Dec-12 22:47pm
Updated 30-Dec-12 0:32am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161021.1 | Last Updated 30 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100