Possible Duplicate:
What is the “best” way to store international addresses in a database?
I would like the application to be global; meaning people from multiple countries (namely Australia, New Zealand, The United States and United Kingdom) can place listings. Because different countries have different formats of postcode, different classifications for areas (Australia and America have states, but places like Canada or the UK are different), how do I effectively store of all of this information?
I just can’t envision in my head what the MySQL database schema for something like this would look like. I don’t need to store any coordinates, just the users country, suburb/city/area and state/province so I can properly classify all of the information and display it on a classified listing.
In some ways, that depends on how much traffic your site is getting. Some will more than likely cringe at this, but if it is a smaller scale website and one is not expecting much traffic growth, it may not be worth normalizing your table. In that case, it may be fine just to store the country as the literal country name.
However, in most cases – especially for repeating data like a Country name – I’ve seen methods that require normalization. For instance, for a quick and simple approach, you can make a dedicated table for each country and assign it a integer value – usually just through auto-incrementing. In that situation, you can then assign each user the associated country id. When querying, simply join the two table together. That is usually a more efficient method.
For a very simply yet useful reference, Learning PHP, MySQL, and Javascript by O’reilly books has a similar example of normalizing tables through the above method. In a majority of cases, one will have repeating data – it’s a matter of minimizing it as well as balancing efficiency and theory with practicality.