Hi, I have a list of partial postcodes (first part) in my database. E.g.: SW19, SW1, etc... I want to find the right partial postcode that belongs to a full postcode. E.g.: SW19 8PR or SW198PR. I can't do a retrieve on my partial postcode list using 'contains' because it is the wrong way around. Turning it around and loop through the partial postcode list, using 'contains' also doesn't give me the desired result, because instead of coming back with the partial postcode "SW19" it comes back with "SW1". Note that the length of the partial postcodes are different from each other and I also don't know how to get the first part from a full postcode.
asked
Sebastiaan van der Plaat
2 answers
2
Hi,
Create an iterator
Determine the max nr of characters of your partial postal code.
Check in the database if there is a partial with your max nr. of characters. E.g. substring($partialcode, 0, $maxlength)
If you do not find something, try to find it with $maxlength-1.
You can also improve performance by doing a count after the retrieve, which will optimize your database query to do a count, instead of querying for all the columns (your entity attributes). A count won't return the object though.
answered
Roeland Salij
0
With substring you can get the part of a string. So substring($fullPostcode,0,length($partialPostcode)) will give you the first number of characters equal to the length of the partial postcode. Then you could do a check if they match.