Hi all
I have built a postcode distance finder for a client. In a nutshell, the user enters their own postcode and chooses a radius to search within (either 5, 10, 50 or 100 miles).
Now everything works, but I am just putting the feelers out to see if the way I have built it could be better done or adapted somewhat to gain best performance so any thoughts are very welcome.
I have obtained a paid for database of UK postcodes. The table contains 1.8 million rows. There is an index on the longitude, latitude and postcode fields.
I have a 2nd table which contains my "shops". Each shop has a 'postcode' and this field has an index on it.
When a user submits my form to search for shops within their postcode search, I do the following:
1) Use a mathematical SQL query (written by the postcode database providers) to obtain all records from the postcode database within the radius set
2) store all of those results into a huge array (a typical array is over 20,000 key/value pairs)
3) Loop through every key/value pair fo the array and query my database to see if a "Shop" has the same postcode
4) if it does, output it into a HTML results list
Now, immediately I know the issue here is that I am running a query for each result in the array but I am sure there would be a better way of doing it - can you help or advise?
Thanks