Database schema store location

Posted 2 years ago by AR

I am creating a database for the shops and their location. I don't want the user to enter what ever city name or country name he wants. So I have created two tables. countries and cities which I have the country_id in the cities table to link the city to the country table.

So in my shop table I have a city_id which then I can access it in my view with $shop->city to get for example "New York" and then I call $city->country to get "USA". Then I display them like "New York, USA".

Is this the right approach to do it? I mean the last part which is $shop->city and $city->country or there is a better way?

Please advice

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.