Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top