SOLVED: odering by distance of two points.
Posted: Tue Sep 19, 2006 4:43 am
Hello all!
I'm having problems using a mathematical SELECT, I've never actually done one so this could be all totally wrong.
cue awesome paint diagram:

what I'm doing is simple pythagoras: squaring the difference between the row `map_x` (destination on the diagram) and the origin x and then squaring the row `map_y` and the origin y then finding the square route of the sum of the two numbers and trying to ORDER BYthat number, ie from nearest to furthest.
Any clues would be greatly appreciated
I'm having problems using a mathematical SELECT, I've never actually done one so this could be all totally wrong.
Code: Select all
$x=$panorama['map_x']; // pull out the origin x
$y=$panorama['map_y']; //pull out the origin y
$panorama_rs=mysql_query("select * FROM `pa_panoramas` order by abs(sqrt((($x-`map_x`)*($x-`map_x`))+(($y-`map_y`)*($y-`map_y`)))) ASC");what I'm doing is simple pythagoras: squaring the difference between the row `map_x` (destination on the diagram) and the origin x and then squaring the row `map_y` and the origin y then finding the square route of the sum of the two numbers and trying to ORDER BYthat number, ie from nearest to furthest.
Any clues would be greatly appreciated