0

I'm creating a Google Map page to show the nearest people to a provided centre point. I send the centre coords via fetch to my server php, perform the mysql query and get the response back (name, lat, long, website-url, distance). Is it possible to send the SQL response back as some sort of JSON object, or something like that, which can be used directly in the javascript, or do I have to stringify as csv data and then parse in the javascript side to recreate the object there? Or is there a better, alternative approach I should have considered?

NeilM
  • 1
  • 1
    `Is it possible to send the SQL response back as some sort of JSON object`...yes. json_encode on the php side, JSON.parse on the JavaScript side – ADyson Mar 15 '21 at 21:59
  • 1
    [PHP json_encode()](https://www.php.net/manual/fr/function.json-encode.php) and [JS JSON.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) – Louys Patrice Bessette Mar 15 '21 at 22:03
  • 1
    https://stackoverflow.com/questions/3351882/how-to-convert-mysqli-result-to-json – Dharman Mar 15 '21 at 22:07
  • Thanks for the feedback. I have had a successful day with your advice. – NeilM Mar 16 '21 at 22:03

0 Answers0