質問

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