SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Thread: Postcode System

  1. #1
    SitePoint Enthusiast calumb's Avatar
    Join Date
    Apr 2004
    Location
    Uk
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Postcode System

    Hi there

    Does anyone have experience using a "search by postcode system" in php and or MySQL.

    Is there a system that postcodes can work by, and does anyone have expereince or know of ways of implementing using PHP.

    Not 100% this is the right thread. But we'll see.

    ThanksIA. Cal

  2. #2
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you be more specific? Do you mean searching for a particular format, or searching for the first 2 letters to check the origin of the postcode? You could also mean just a standard search in MySQL.

    PHP Code:
    $qry "SELECT postcodefield FROM tablename WHERE postcodefield LIKE `%blahblah%`"
    What exactly are you trying to do?
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  3. #3
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello mate.
    my company was wanting to implment a postcode checker for broadband availabilty..ie, for users to see if broadband was available in an area. I see you are in the UK, so this will deffo apply to you.
    Firstly, it is very much possible, you would enter all the postcodes into you db, and search in the way F4nat1c has mentioned.

    We enountered two problems though:
    a) There are +-27 million postcodes in the UK
    b) Royal Mail mail charge about 2500 for the full list and about 1000 a year to keep it updated
    c) You need a very specail/robust system to deal with the search due to the vast number of postcodes.

    But to answer your question, yes, it can be done using PHP and MySql

    Does this help ?
    If you are just looking for the broader area postcode ie: SW19, WC1 etc, then I actually did come across a list foir this, I will see if I can find it again

  4. #4
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol i wouldnt recommend the first one, very confusing.

    If you were to use one of these lists, calumb, how would you implement it? You would probably need to save all of the postcodes as a textfile, then search the textfile for a corresponding postcode. I can't see another good way to do this.
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  6. #6
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by F4nat1c
    You would probably need to save all of the postcodes as a textfile, then search the textfile for a corresponding postcode.
    Thats what we tried to do, but it crashed everytime due to the vast number

  7. #7
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How did you solve it? Whay method did you use?
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  8. #8
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, thats the problem...we havent yet...
    But the site runs off a CMS, so this could have been a big factor towards the crashing...???
    But it was going to use SQL queries to search through these poscodes, using something very similar to what you suggested originally..
    Sorry, not meaning that the method you suggested wouldnt work, its just the sheer volume of postcodes

  9. #9
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,198
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    A php class together with a db could solve the speed issue...

    Just divide the list, into several tables depending on the zip ranges. Then use the class to select the correct table to search.

    Though in the end it depends on what information you need from the zip codes, if its just to validate it against the rest of the information the user has inputted the above solution would work.

  10. #10
    SitePoint Enthusiast calumb's Avatar
    Join Date
    Apr 2004
    Location
    Uk
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys cheers for all your posts here, there is an awful lot of postcodes there =P

    Is there a logical system or rule to follow for deciding which postcodes are close to each other.

    For example our shop is located in CV1 but the customer is in SW1, is there a rule or calculation to give an estimate of how far these two points are?

    Cheers

  11. #11
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello again...
    I am not sure if there is, all I know, is for london, the postcodes are obviously SW for south-west, WC for west-central E1 for east etc, and then the further you go out, the higher the numbers get. eg, SW1 is Victoria/Green Park (central), then SW19 is Wimbledon, which is a lot further out... I know its not exactly what you were asking, but it may help?

  12. #12
    SitePoint Enthusiast calumb's Avatar
    Join Date
    Apr 2004
    Location
    Uk
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dashman, Yh I can see what your saying, I might just be really general and cut the postcode down to the first two letters and then try and figure out some sort of plotting system... thanks

  13. #13
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No probs

    Check this out ... I looked into it in detail, but it may be what you are looking for...
    Good luck!

  14. #14
    is_empty(2); foofoonet's Avatar
    Join Date
    Mar 2006
    Posts
    1,000
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have done something similar on a very small scale though...

    I think you might seperate the tables out, eg B12 1TT, create a table with just B12s in them.

    Make sure you index what is left like "1TT".

    Now, get your users to enter the first part of the pcode, lot easier to regex that. Check they get the first bit right before wasting much resources on a full search. IMO users get so much wrong when you ask for a pcode, ucase, letter O instead of 0, Z instead of 2, it can be a right usability balls up.

    Although pcodes change like the wind, the prefixes dont, you could cache that list an array (or search for table names - is it possible to do that?)

    If they manage to get the prefix right, then ok, let them search your indexed table, but that means having a 2 stage lookup, UNLESS you think this could be a candidate for an (gasp) AJAX solution.

    Would that werk?

    Could be done in OOP v nicely...

  15. #15
    SitePoint Enthusiast calumb's Avatar
    Join Date
    Apr 2004
    Location
    Uk
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone I managed to do it following Dashman's link, just the job. Thanks again

  16. #16
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good stuff


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •