How to sort complicated PHP queries. $ Latitude =$ _ GET ['Y'];
$ Longpolling = $ _ GET ['x'];
$ Distance = 500;
$ SQL = "select * from ". $ GLOBALS ['ecs']-> table ('weixin _ map '). "where sqrt ((((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180 )*((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180) + (((". $ latitude. "-Latitude) * PI () * 12656/180 )*((". $ latitude. "-Latitude) * PI () * 12656/180)/2 <". $ distance;
I found the merchant information 500 km ago, but I cannot sort it by distance.
Check the specific method.
Reply to discussion (solution)
How to Use array to calculate the distance of all information and then sort it again.
My idea is to create an array, calculate each piece of data, calculate the distance, and then sort the data.
Who can help write it out...
Select *, sqrt ((((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180 )*((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180) + (((". $ latitude. "-Latitude) * PI () * 12656/180 )*((". $ latitude. "-Latitude) * PI () * 12656/180)/2 as dis
Order by dis having dis in the from table <= 500
Select *, sqrt ((((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180 )*((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180) + (((". $ latitude. "-Latitude) * PI () * 12656/180 )*((". $ latitude. "-Latitude) * PI () * 12656/180)/2 as dis
Order by dis having dis in the from table <= 500
Error occurred, prompting having dis errno
Select *, sqrt ((((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180 )*((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180) + (((". $ latitude. "-Latitude) * PI () * 12656/180 )*((". $ latitude. "-Latitude) * PI () * 12656/180)/2 as dis
Order by dis having dis in the from table <= 500
$ SQL = "select *, sqrt ((((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180 )*((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180) + (((". $ latitude. "-Latitude) * PI () * 12656/180 )*((". $ latitude. "-Latitude) * PI () * 12656/180)/2 as dis
From ". $ GLOBALS ['ecs']-> table ('weixin _ map')." group by dis having dis <". $ distance;
This can be sorted, but the opposite is true ..
Select *, sqrt ((((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180 )*((". $ longpolling. "-longpolling) * PI () * 12656 * cos (((". $ latitude. "+ Latitude)/2) * PI ()/180)/180) + (((". $ latitude. "-Latitude) * PI () * 12656/180 )*((". $ latitude. "-Latitude) * PI () * 12656/180)/2 as dis
From ". $ GLOBALS ['ecs']-> table ('weixin _ map')." group by dis desc having dis <". $ distance;
Solution.