"advanced maths" in queries
Posted: Sat Dec 09, 2006 2:47 am
So heres the deal, in my code I have:
Now in my database, in my player table theres a posx and posy position.
Now I have a viewport of 550x350 pixels which is peg registered (player is always centered).
Now to grab the other players right now I do a simple query and grab all the players whos posx and posy are within that 550x350 rectangle around you.
One problem with that is that it doesnt return them in order of distance from you.
I was thinking of changing that query to order by distance, which would mean SQRT( ($posx - posx)^2 + ($posy - posy)^2), now heres my question:
is it ok to do a query where "distance" is less than 275, ordered by distance? Or would that slow down the query a lot?
Code: Select all
$posx; //player's X position
$posy; //player's Y positionNow I have a viewport of 550x350 pixels which is peg registered (player is always centered).
Now to grab the other players right now I do a simple query and grab all the players whos posx and posy are within that 550x350 rectangle around you.
One problem with that is that it doesnt return them in order of distance from you.
I was thinking of changing that query to order by distance, which would mean SQRT( ($posx - posx)^2 + ($posy - posy)^2), now heres my question:
is it ok to do a query where "distance" is less than 275, ordered by distance? Or would that slow down the query a lot?