scotchegg78 Posted October 29, 2007 Share Posted October 29, 2007 Hi guys, Is there way i can make mysql only return my postcode search for one char and 2 numbers/ints? $query_qryData .= " CompanyPostCode LIKE '" . $colname_qryData . "%' AND"; returns all the postcodes starting with the letter B, inclucing invalide B and another letter postcodes like BA etc. of course $query_qryData .= " CompanyPostCode LIKE '" . $colname_qryData . " ' AND"; will just return post codes with the letter B, but postcode in the uk all haev the format of 1 or 2 letters, followed by 1 or 2 numbers. thanks Link to comment https://forums.phpfreaks.com/topic/75191-post-code-search-to-return-b-b18-b34-etc-not-ba12-ba1-etc-etc/ Share on other sites More sharing options...
scotchegg78 Posted October 29, 2007 Author Share Posted October 29, 2007 I have used this, is this correct? is there a better way? Query = " CompanyPostCode LIKE '" . $colname_qryData . "%' AND SUBSTRING(CompanyPostCode,2,1) BETWEEN '0' AND '9' AND"; I suspect this leaves out any postcodes with just B though? is there a way to test if its NOT a char in the substring and not if its a number? Link to comment https://forums.phpfreaks.com/topic/75191-post-code-search-to-return-b-b18-b34-etc-not-ba12-ba1-etc-etc/#findComment-380282 Share on other sites More sharing options...
fenway Posted October 29, 2007 Share Posted October 29, 2007 Yes... with REGEXP. Link to comment https://forums.phpfreaks.com/topic/75191-post-code-search-to-return-b-b18-b34-etc-not-ba12-ba1-etc-etc/#findComment-380380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.