Ditching characters in a value
Posted: Mon Sep 06, 2004 7:07 am
How do I ditch the last 2 characters in a value?
I have built a MYSQL database driven website based on the common postcode for an area. By that I mean the county code (say GL) the county split (say 2) and the district (say 4) - this example would have a common postcode of GL2 4 (an actual postcode would be GL2 4AA for example).
The idea is that a user enters a postcode on a form, PHP converts the data to a variable, the common postcode for that area is identified from the variable is sent to the MYSQL database and the information is returned to user.
In an ideal world I would simply use a select statement that only reads the first 4 digits of the variable (such as LEFT($value,4)) but this falls down as unfortunately some of the county splits are 2 digits long (thus postcodes such as GL50 4AA).
What I need is a way to disregard the last two digits (letters) of the postcode to extract the common postcode. This is the only foolproof filter I can identify.
Please let me know if you have any ideas how to do this - I have tried RIGHT($value,-2) in my select statement but it did not work!
Thanks.
I have built a MYSQL database driven website based on the common postcode for an area. By that I mean the county code (say GL) the county split (say 2) and the district (say 4) - this example would have a common postcode of GL2 4 (an actual postcode would be GL2 4AA for example).
The idea is that a user enters a postcode on a form, PHP converts the data to a variable, the common postcode for that area is identified from the variable is sent to the MYSQL database and the information is returned to user.
In an ideal world I would simply use a select statement that only reads the first 4 digits of the variable (such as LEFT($value,4)) but this falls down as unfortunately some of the county splits are 2 digits long (thus postcodes such as GL50 4AA).
What I need is a way to disregard the last two digits (letters) of the postcode to extract the common postcode. This is the only foolproof filter I can identify.
Please let me know if you have any ideas how to do this - I have tried RIGHT($value,-2) in my select statement but it did not work!
Thanks.