Jump to content

Database Structure Help, Custom PC shopping cart Database problem? :(


Recommended Posts

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.

 

db_structure.gif

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

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.

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

 

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

 

....

 

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.