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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top