adam84 Posted July 14, 2008 Share Posted July 14, 2008 This deals with Canadian Postal Code, for some reason we have a ton of them. On my site, I have a search form, where the user enters their seach criteria, they enter in the postal code (X0X 0X0), then they select the distance they wanna search within (10km, 25km, 50km, etc). When the user submits the form, I collect all the submitted data, and create my sql statement. I then call a function the queries my postal code database and the function returns all the postal codes in an array that are within the distance range (I didnt write the function). For instance I got over 150 different postal codes returned for a simple 25km search. This is pretty much how my sql statement looks, except each postal code is different. My question is, is this how I should be doing this using the 'IN' or is there another more efficient way of doing thisa dn speeding it up. SELECT * FROM userProfile WHERE userGender = 'F' AND age > 19 AND age < 31 AND pCode IN ( 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8', 'N6H 3K6, 'N7H 3K7', 'N8H 3K8') *Sample query, can post an actual one later, I dont have the files on me Link to comment https://forums.phpfreaks.com/topic/114692-speeding-up-geodb-query/ Share on other sites More sharing options...
fenway Posted July 14, 2008 Share Posted July 14, 2008 Depends what EXPLAIN says.... but that's not really how you're supposed to look up things within a given radius... there is an entire set of spatial functions for this. Link to comment https://forums.phpfreaks.com/topic/114692-speeding-up-geodb-query/#findComment-589814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.