I have a database table which link locations together; a location can be in a location, which can be inside another location.
location (, ....) loc
There's a good-looking article over at mysql.com outlining various ways of managing hierarchical data. I think it provides a full solution to your question, and shows various less simple, but faster approaches (e.g. Nested Sets).