MySQL Forums
Forum List  »  Newbie

How to check if `Pcode` from the table is in the string 'AB134DE'
Posted by: Jason Carroll
Date: September 16, 2014 09:49AM

How would I check if `Pcode` from the table is in the string 'AB134DE'

`Pcode` is the field name in the DB, and 'AB134DE' is the string that was entered in my form on the website.

These are postcodes in the UK, my table has the start of all postcodes, i.e.

AB10
AB11
AB12
AB13
AB14

for example...

So if someone was to enter say 'AB134DE' (without the quotes)

I wish to check that the postcode is valid be checking if the content of the table data is in the string. (not if the string is in the table data, which is the normal way)

I can not really have a php script sort this out as some postcodes are like...

SW1A1AB
and
SW121AB

so trimming the string to just 3 or 4 characters will cause more than one result to be returned in some cases and the wrong postcode being used.

So looking for a way to reverse the query to search the other way around.

SELECT `Pcode` FROM `postcodes` WHERE `%Pcode%` LIKE 'AB134DE'
but of course this does not work.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.