2

I do a query to fetch all restaurants in my mysql db. After that, I sort these on distance to the user with the PHP usort function, based on their lat/lng coordinates.

What's the most efficient way to paginate the usorted array, without needing to do a query and usort on all items each new paginated page?

2
  • Can you do the sorting in MySQL? Commented Nov 20, 2012 at 7:25
  • Don't think so, I use the Haversine formula to calculate the distance between to pairs of lat/lng coordinates. Commented Nov 20, 2012 at 7:26

1 Answer 1

0

You shouldn't be doing this in PHP. MySQL will do a much better job sorting your results set.

There's a paper here about doing this in MySQL, which is referenced here.

Regardless of which formula you're using, you should be able to do this with MySQL, even if you have to used stored procedures.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Looks exactly like where I'm looking for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.