Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top