Jump to content

[SOLVED] Whats the best datatype for my problem?


Recommended Posts

Ok, so i have a huge database i will be building for work. Pretty much, I have 2 things that i'm not sure how to approach.

 

I have a table called hotel. It has 2 rows. One row is called HOTEL_ID. The other is HOTEL_NAME.

I have another table thats the same but is restaurants instead of hotels.

 

 

Now, I have a third table called citySmall_table and it will have a few different rows. My question is that I want 2 rows that will be called HOTEL_ID and RESTAURANT_ID inside this citySmall_table that will be foreign keys to the other tables.

 

example: So if city A has restaurant 1, 4, and 6, i would want to add 1, 4, and 6 to my citySmall_table to the row RESTAURANT_ID.  Follow me?

 

What is the best datatype to do that. I could do character because i can add multiple characters rather than just one, but then how do i use PHP to display that? Usually I pass variables and use a WHERE clause. (WHERE ID=2) to display the information I want.  I don't want to use E_NUM because there will be TONS of restaurants and hotels and that would get to be too big to manage, plus I think that only lets you put one value in the row.

 

 

What is the best way to approach this?

zang8027: For IDs INTEGER datatype is most commonly used (and not without reason, it's the most convenient). Now, the database design you're describing is not the best one. You should rather have two more tables. One that will relate hotels to cities, and one that will relate restaurants to cities.

 

leela: please create your own topic for your question.

No. You don't need one table per city.

You would need something like this

 

table hotels
hotel_id, hotel_name,...
1, 'Excelsior'
2, 'Radison'

table restaurants
restaurant_id, restaurant_name,...
1, 'Pierre\'s'
2, 'Cafe Bene'

table cities
city_id, city_name,...
1, 'New York'
2, 'Boston'

table hotels_to_cities
hotel_id, city_id
1,1   //Excelsior is in NY
2,2   //Radison is in Boston

table restaurants_to_cities
restaurant_id, city_id
1,2  //Pierre's is in Boston
2,1  //Cafe Bene is in NY

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.