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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:10:55+00:00 2026-05-28T01:10:55+00:00

Hi In my data base I have an total 100 locations in this 50

  • 0

Hi In my data base I have an total 100 locations in this 50 locations are nearest to me another 50 locations are longest to me so i want to sort data using this order so here i calculate the distance

$latt=$_REQUEST['latt'];
$long=$_REQUEST['long'];

$start=$_REQUEST['start'];
 function distancefind($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;
      }
}



 $c=0;
    $limt=10;
    if($start!=null)
    {
    $query="select * from  tbl_MapDetails LIMIT $start,$limt";
    }
$result=mysql_query($query);
if($result)
{
while($row=mysql_fetch_array($result))
{

$distance1=distancefind($latt,$long,$row['Latitude'],$row['Longitude'],"");


$message[$c]=array("ID"=>$row['LocationID'],"Address"=>$address,"City"=>$row['City']=($row['City'] != null)?$row['City']:"","State"=>$row['State']=($row['State'] !=null)?$row['State']:"","Country"=>$row['Country']=($row['Country']!=null)?$row['Country']:"","Zip"=>$row['Zip']=($row['Zip'] !=null)?$row['Zip']:"","Country"=>$row['Country']=($row['Country']!=null)?$row['Country']:"","Distance"=>$distance1=($distance1==null)?"0":$distance1,"Latitude"=>$row['Latitude']=($row['Latitude']!=null)?$row['Latitude']:"","Longitude"=>$row['Longitude']=($row['Longitude']!=null)?$row['Longitude']:"","Pic"=>$pic,"rating"=>$row1[0]=($row1[0]!=null)?$row1[0]:"","name"=>$row['LocationName']=($row['LocationName']!=null)?$row['LocationName']:"","note"=>$row['Note']=($row['Note']!=null)?$row['Note']:"","feature1"=>$row['FeatureIcon1']=($row['FeatureIcon1']!=null)?$row['FeatureIcon1']:"","feature2"=>$row['FeatureIcon2']=($row['FeatureIcon2']!=null)?$row['FeatureIcon2']:"","feature3"=>$row['FeatureIcon3']=($row['FeatureIcon3']!=null)?$row['FeatureIcon3']:"","selectLogo"=>$row['SelectIcon']=($row['SelectIcon']!=null)?$row['SelectIcon']:"");
$c++;
}

so here i get each time i get 10 locations so message array data start with nearest to longest how can i check please guide me

Thanks for advance

  • 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-28T01:10:56+00:00Added an answer on May 28, 2026 at 1:10 am

    If you want to do the ordering first and the limiting second (ie pick the $limt closest things (offset by $start) to ($lat,$long)), you can do it within MySQL:

    $query = "SELECT *,
     ((ACOS(  SIN($lat*PI()/180)*SIN(Latitude*PI()/180) 
            + COS($lat*PI()/180)*COS(Latitude*PI()/180)*COS(($long-Longitude)*PI()/180
            )
      ) * 180/PI()
     )*60 * 1.1515) AS dist
    FROM  tbl_MapDetails
    ORDER BY dist 
    LIMIT $start,$limt";
    

    But if you want to do the $limt first and then sort by distance (so pick $limt items and then order them by distance — may not contain the closest location though), use @SergeyRatnikov’s answer, or you need to do a nested select as:

    SELECT * from
     (SELECT *,
       ...[distancecalculation]... AS dist
       FROM tbl_MapDetails
       LIMIT $start,$limt)
    ORDER BY dist
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database i want to select data from data base of current
I have table in data base name train delay, with columns train number(int), DelayTime(int),
I have a file data.base which looks like: 1234 XXXX 4321 XXXX 9884 ZZZZ
I have created a data base that comes in an installer that runs as
I have serialize values in data base, i fetch them from database then when
I have a table in my data base that has three columns: Screen, Icon,
I have a Database named CarsType.accdb there are four fields in the data base
In my model I have: class Log < ActiveRecord::Base serialize :data ... def self.recover(table_name,
I have HH:mm:ss from database with HH is more than 100. I have data
i have total 70,000 records in database. currently i displays all the records in

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.