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
https://forums.phpfreaks.com/topic/149768-help-can-you-put-2-values-in-1-field/
Share on other sites

  Quote
... 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).

 

  Quote
... 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.

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.