ldoozer Posted October 21, 2009 Share Posted October 21, 2009 Hi all I am trying to develop a small postcode lookup so taht people can type in their full postcode and hit go, and they are send to a page where they see the results to see if something is happening in their area. The problem is I only want to query the first part of the postcode i.e. S10 or S1 and disregard the rest. I have a script that will format the input from the user to a standard format (http://www.braemoor.co.uk/software/postcodes.shtml) but what i need to know is how to query there database form there: Would it be something like: $query = "SELECT * FROM tablename WHERE LEFT(PostCode, LENGTH(PostCode ) - 3 )IN('$postcode')"; Many thanks Steve Quote Link to comment https://forums.phpfreaks.com/topic/178455-postcode-lookup/ Share on other sites More sharing options...
kickstart Posted October 21, 2009 Share Posted October 21, 2009 Hi How many postcodes do you want to check at once? If just one then:- $query = "SELECT * FROM tablename WHERE PostCode LIKE '".$postcode."%')"; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/178455-postcode-lookup/#findComment-941061 Share on other sites More sharing options...
ldoozer Posted October 21, 2009 Author Share Posted October 21, 2009 Thanks for the reply Is there a problem with that though because it could return both S2 and S22? Quote Link to comment https://forums.phpfreaks.com/topic/178455-postcode-lookup/#findComment-941063 Share on other sites More sharing options...
kickstart Posted October 21, 2009 Share Posted October 21, 2009 Hi It could (which depends on whether you want S2 and S22 returned), but if you want to suppress S22 then just add a space between the first part of the postcode and the *. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/178455-postcode-lookup/#findComment-941079 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.