Home > Archive > PHP Language > May 2007 > How to ignore second letter in first part of UK postcodes?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to ignore second letter in first part of UK postcodes?
|
|
| leader@congress.hotmail.com 2007-05-19, 3:58 am |
| I've inherited a php/mysql app which sorts and displays UK postcodes.
When sorting, it uses
SELECT... WHERE postcode like "$postcode%"
and for a $postcode of, say E, this works Ok except it brings to
screen everything starting EH (for Edinburgh) *and* everything
starting E (for East London). I need to refine this further. How do
I bring to screen *only* those starting, say, E (for East London), S
for Sheffield and G for Glasgow, etc?
I think I need to be able to ignore any postcode whose second letter
is *not* a letter but is a number or space, or blank, but I don't know
how to do this.
Any help gratefully received.
| |
|
| > I've inherited a php/mysql app which sorts and displays UK postcodes.
> When sorting, it uses
> SELECT... WHERE postcode like "$postcode%"
> and for a $postcode of, say E, this works Ok except it brings to
> screen everything starting EH (for Edinburgh) *and* everything
> starting E (for East London). I need to refine this further. How do
> I bring to screen *only* those starting, say, E (for East London), S
> for Sheffield and G for Glasgow, etc?
> I think I need to be able to ignore any postcode whose second letter
> is *not* a letter but is a number or space, or blank, but I don't know
> how to do this.
You can use regular expressions in mysql queries. Which could be 1 way of
doing what you wish.
| |
| joboils@hotmail.com 2007-05-27, 10:03 pm |
| On Sun, 27 May 2007 00:31:45 +0100, "peter" <submit@flexiwebhost.com>
wrote:
>
>You can use regular expressions in mysql queries. Which could be 1 way of
>doing what you wish.
>
Thank you for your response. Someone else mentioned the ctype_***()
functions and they look just the job.
| |
| Gleep 2007-05-27, 10:03 pm |
| On Sun, 27 May 2007 00:31:45 +0100, "peter" <submit@flexiwebhost.com> wrote:
>
>You can use regular expressions in mysql queries. Which could be 1 way of
>doing what you wish.
>
try where postcode REGEXP '^$postcode( |[0-9])+';
means get first letter the second letter can be a space or number
| |
| Gleep 2007-05-27, 10:03 pm |
| On Sun, 27 May 2007 16:46:34 GMT, joboils@hotmail.com wrote:
>On Sun, 27 May 2007 00:31:45 +0100, "peter" <submit@flexiwebhost.com>
>wrote:
>
>Thank you for your response. Someone else mentioned the ctype_***()
>functions and they look just the job.
wait think the last post was wrong
try
where postcode REGEXP '^$postcode( |\d)';
you should also consider string case
$postcode = strtoupper($postcode);
select ..... WHERE UPPER(postcode) REGEXP '^$postcode( |\d)' ;
|
|
|
|
|