bri0987 Posted October 16, 2007 Share Posted October 16, 2007 I'm working on making a shopping cart using Php and MySQL. Building a Custom PC shopping cart... I'm getting the pages put together and putting info into the database AND KNOW I have been hit with a major problem. (I provided an image below so you can see the structure)... When I start pulling components into the pages, I will get every component for every product... What I need is... Some components for certain PC products. So some PC products may have the same components as other products, but it may only have a few. I'm stuck with a many to many relationship here. I cant figure other how to fix it, or maybe put something in between them to correct it. (I could assign each component to it's own PC product, but if that component is for ALL of the PC products, I will have to insert that SAME data 5 to 10 times AND then it would be a one to one relationship). This is so frustrating. Can anyone help me figure this out. Or please give me some pointers. Quote Link to comment https://forums.phpfreaks.com/topic/73402-database-structure-help-custom-pc-shopping-cart-database-problem/ Share on other sites More sharing options...
fenway Posted October 16, 2007 Share Posted October 16, 2007 Many-to-many is right... relate components to products, don't dupe anything. Quote Link to comment https://forums.phpfreaks.com/topic/73402-database-structure-help-custom-pc-shopping-cart-database-problem/#findComment-370662 Share on other sites More sharing options...
bri0987 Posted October 16, 2007 Author Share Posted October 16, 2007 Fenway... But what I need is a: one to many between Components and Products... Reason being is because: (The Right way: The way I need it to work) Product number 1 -needs- Component A and B Product number 2 -needs- Component A and C Product number 3 -needs- Component A, B, and C **** (THE WRONG WAY: The way it currently works) Right now my Products look like this: Product number 1: Component A,B,C Product number 2: Component A,B,C Product number 3: Component A,B,C >> or is also work like this: Product number 1: Component A Product number 1: Component B Product number 1: Component C Quote Link to comment https://forums.phpfreaks.com/topic/73402-database-structure-help-custom-pc-shopping-cart-database-problem/#findComment-370871 Share on other sites More sharing options...
fenway Posted October 16, 2007 Share Posted October 16, 2007 This: Product number 1 -needs- Component A and B Product number 2 -needs- Component A and C Product number 3 -needs- Component A, B, and C requires this: Product number 1: Component A Product number 1: Component B Product number 1: Component C .... in the relating table. Doesn't matter if it's one to many or many-to-many. Quote Link to comment https://forums.phpfreaks.com/topic/73402-database-structure-help-custom-pc-shopping-cart-database-problem/#findComment-370874 Share on other sites More sharing options...
bri0987 Posted October 16, 2007 Author Share Posted October 16, 2007 Each product will have many different processors and motherboards and RAM to choose from. When someone goes to the site they will be picking from a list for each component: PC PRODUCT ONE .... Processor: o Intel Quad-Core 2.4 etc. o Intel Quad-Core 2.6 etc. o etc. Motherboard: o Asus Intel LGA 775 etc. o eVGA ATX 1066mhz etc. o etc. etc. etc. etc. A good example of what the shopping cart will function like is at Alienware.com just go there and click onto a product and see how you can choose different components. ....................... Also could I just make a relational table in between Products and components in the database. What I mean is. Could I make a table called: tbl_Relations In that Table it would look like this: Product_ID: 22 Component_ID: 1 Product_ID: 22 Component_ID: 2 Product_ID: 22 Component_ID: 3 Product_ID: 22 Component_ID: 4 Product_ID: 17 Component_ID: 2 Product_ID: 17 Component_ID: 3 Product_ID: 17 Component_ID: 5 I think that might do it... what do you think Quote Link to comment https://forums.phpfreaks.com/topic/73402-database-structure-help-custom-pc-shopping-cart-database-problem/#findComment-370878 Share on other sites More sharing options...
bri0987 Posted October 17, 2007 Author Share Posted October 17, 2007 I have this already: <p>Match this Component with 1 or more Products.</p> <?php // 3. Perform database query mysql_select_db($database_DM_database, $DM_database); $db_result1 = mysql_query("SELECT tblproducts.Product_ID, tblproducts.Product_Name FROM tblproducts", $DM_database); if (!$db_result1) { die("Database query failed: " . mysql_error()); } ?> <p>Content </p> <form name="form1" method="post" action=""> <p> <?php // 4. Use database retured data while ($row = mysql_fetch_array($db_result1)) { echo "<input type=\"checkbox\" name=\"" . $row["Product_ID"] . "\" value=\"checkbox\" />" . " " . $row["Product_Name"] . " <br />" ; } ?> <?php if (isset($_GET['Component_ID'])) { $Component_ID = (get_magic_quotes_gpc()) ? $_GET['Component_ID'] : addslashes($_GET['Component_ID']); } ?> <input type="hidden" name="Component_ID" value="<?php if (isset($Component_ID)) { echo $Component_ID; }?>" /> </p> <p> <input type="submit" value="Submit" /> </p> </form> How do I make it submit into the database more then one field. For example: Currently there are 4 products. If I select all 4 of the products, I need PHP to insert 4 different times into the database Looking like this: Product_ID ....... Component_ID 1 ..................... 1 2 ..................... 1 3 ..................... 1 4 ..................... 1 What does the php code for that look like, how can I write this php... .... Quote Link to comment https://forums.phpfreaks.com/topic/73402-database-structure-help-custom-pc-shopping-cart-database-problem/#findComment-371217 Share on other sites More sharing options...
fenway Posted October 17, 2007 Share Posted October 17, 2007 It will "submit" as many fields as you POST to it... and yes, you'll need to insert multiple records. Quote Link to comment https://forums.phpfreaks.com/topic/73402-database-structure-help-custom-pc-shopping-cart-database-problem/#findComment-371533 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.