Click here to Skip to main content
Rate this: bad
good
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 ...here 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 ?
<br>
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 23:47pm
Edited 30-Dec-12 1:32am
(no name)500.7K
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,554
1 OriginalGriff 6,258
2 Peter Leow 2,534
3 Maciej Los 2,308
4 Abhinav S 2,274


Advertise | Privacy | Mobile
Web01 | 2.8.150414.1 | Last Updated 30 Dec 2012
Copyright © CodeProject, 1999-2015
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