Assuming you have made the result set from your SQL query as well as the users location available to the client side JavaScript, you could easily sort your locations by distance using the haversineDistance function inside of JavaScripts native array sort function.
generative typography