Web Analytics Made Easy -
StatCounter php question - postcode ranges - CodingForum


No announcement yet.

php question - postcode ranges

  • Filter
  • Time
  • Show
Clear All
new posts

  • php question - postcode ranges

    im creating a little shopping app in php mysql where the user enters thier postcode and the price is calculated depending on this. (search the poscode table which is linked to the shipping zone table where i find the cost)

    in the backend the admin will be able to specify the shipping zones and several ranges of postal code for these zones..
    i was thinking of having a postcode table and letting the admin use a multiple select box to select ranges for that zone.... but there are soo many of them 9000+

    therefore my question.. if i allow the admin to specify ranges in the backend eg
    then how would the search work on the front end? for example if the user enters a postcode of 2598 what sort of logic would i use to find what zone that is in?

    any help appreciated!

  • #2
    Welcome here!

    i don't really understand the question.

    normally, you would have a table with 1 row for each postcode.
    this table then has a structure like
    postcode --> primary key
    zone --> foreign key
    postcodelabel --> some text like the town name or so

    to get the zone, you then simply have

    select zone from yourtable where postcode=$theenteredpostcode

    all info about the zone, like the transportation fee will be stored in a second table wth a structure like
    zone --> primary key
    transport_price --> price in cents or dollars/euro
    zonelabel --> the regional description or so

    you can then join these two table on the zone columns to get the transportation price for an entered postcode.

    to link the postcodes to a zone, you can still do this in badges. with an update like

    update postcodetable set zone = 1 where postcode between 2000 and 3000
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html