beer Posted March 17, 2009 Share Posted March 17, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/149768-help-can-you-put-2-values-in-1-field/ Share on other sites More sharing options...
xylex Posted March 17, 2009 Share Posted March 17, 2009 You need a many to many relationship setup. Scrap your categories column in toys and add a table of toys->categories, and query off of that. Quote Link to comment https://forums.phpfreaks.com/topic/149768-help-can-you-put-2-values-in-1-field/#findComment-786500 Share on other sites More sharing options...
beer Posted March 21, 2009 Author Share Posted March 21, 2009 ... 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. Quote Link to comment https://forums.phpfreaks.com/topic/149768-help-can-you-put-2-values-in-1-field/#findComment-790124 Share on other sites More sharing options...
Maq Posted March 21, 2009 Share Posted March 21, 2009 You should really look into Database normalization. Quote Link to comment https://forums.phpfreaks.com/topic/149768-help-can-you-put-2-values-in-1-field/#findComment-790129 Share on other sites More sharing options...
beer Posted March 24, 2009 Author Share Posted March 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/149768-help-can-you-put-2-values-in-1-field/#findComment-792247 Share on other sites More sharing options...
Daniel0 Posted March 24, 2009 Share Posted March 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/149768-help-can-you-put-2-values-in-1-field/#findComment-792579 Share on other sites More sharing options...
beer Posted March 26, 2009 Author Share Posted March 26, 2009 Oh I got it finally!!! Thank you: xylex, Maq, and Daniel0 for your help. My problem has been solved. Thank you phpfreaks! Quote Link to comment https://forums.phpfreaks.com/topic/149768-help-can-you-put-2-values-in-1-field/#findComment-794271 Share on other sites More sharing options...
Maq Posted March 26, 2009 Share Posted March 26, 2009 I love beer... Quote Link to comment https://forums.phpfreaks.com/topic/149768-help-can-you-put-2-values-in-1-field/#findComment-794427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.