Jump to content

Post Code search to return B, B18, B34 etc, not BA12 BA1, etc etc


scotchegg78

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.