Jump to content

Help! Can You Put 2 Values in 1 Field?


beer

Recommended Posts

Hi, I have a database design question,

 

My tables:

 

toys

models

categories

 

TOYS for sale: people, cars, boats, guns, and airplanes.

 

 

MODELS under these TOYS:

 

people -> US marine, He-Man action-figure, etc...

 

cars -> F1 car, 1960 Ferrari, Tricycle War Vehicle, etc...

 

boats -> Spyder89 Racing Boat, Destroyer, Batman's Boat, etc...

 

guns -> Pistol, Bazooka, etc...

 

airplanes -> F16, Cessna, No-Engine Sports Glider, Blimp, etc...

 

 

CATEGORIES:

 

Military Toys

Sports Toys

Cartoon Network Toys

 

 

If a visitor ONLY wants to see Military toys, he/she can click: Category: MILITARY TOYS.

 

My code: SELECT * FROM toys WHERE category_id = $_GET['cat'] = 1 (Military has id=1)

 

But these same toys also BELONG to SPORTS toys. (category = 2)

 

So I can't SUMMON these TOYS anymore because their field is ALREADY POPULATED with a CATEGORY_ID = 1 (Military), meaning, their relationship is with the MILITARY CATEGORY already.

 

What can I do in my design so that these toys also show up under the SPORTS TOYS category?

 

I've seen it done in BIG webpages, I just don't know how they did it.

 

HELP!

Link to comment
Share on other sites

... Scrap your categories column in toys...

 

Ok, I'm going to scrap off the CATEGORIES_ID (the relational field of the Table: toys to the Table: Categories).

 

... and add a table of toys->categories, and query off of that.

 

So I will make a NEW TABLE named: toys->categories ? Can you suggest a better name for the table?

 

Thanks a lot.

 

Link to comment
Share on other sites

Hey man thanks for that link, but I didn't understand what you meant in that article.

 

Are you saying that I shouldn't use Many-to-Many relationships?

 

If not, how do you exactly design a many-to-many relationship database?

 

Appreciate your help kind man.

Link to comment
Share on other sites

You make a many-to-many relationship by having an intermediate linking table, C, that stores the relationship between rows in A and rows in B such that each row in C stores the PK of a row x∈A and the PK of a row y∈B such that x and y are related.

Link to comment
Share on other sites

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.