SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm designing a custom shopping cart. I know how I want it to work, but he's got a custom detail I'm going to have to build it around.

    This is the fact that he's wants EVERY product to have a unlimited number of options. Here is an example:

    Product 1, $10.50, Great Digging Tool, 5lbs.,

    option1
    option2
    option3
    option4
    option5
    option6

    and then mabey this:

    Product 1, $8.55, Lightweight Digging Tool, 2lbs.,

    option1
    option2

    One of his products goes all the way through 20 different options! But, mostly they range from 1-6.

    I'm going to list them in a dropdown, but I really wanted ot know what the best method would be to do this.

    here's my current table structure:

    /*
    This cart is going to use the following tables:

    Product
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ID | Product_Cat | weight | price | per_box | nose | base | pic | comments | grain
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | 1 | 5 | 10.50 | 100 | LFN | BB | ../../images/bullet.gif | Good shooter in 44 | 250
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    *******************************************

    Product_Cat
    ------------------------------------------------------------
    ID | Name
    ------------------------------------------------------------
    1 | 22 Caliber
    ----------------------------------------------------------

    *******************************************

    Options
    -----------------------------------------------------------ID | Product_ID | Value
    -----------------------------------------------------------1 | 5 | .452
    -----------------------------------------------------------



    ********************************************

    Shopper
    -----------------------------------------------------------
    ID | shop_id | Product_ID | QTY | option_id
    -----------------------------------------------------------1 | 24552155436 | 5 | 1 | 6
    -----------------------------------------------------------

    */

    Then get the data.... you know the drill...

    thanx for any help!

    God Bless

    Alex
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could store all of the options in one text column as one big blob with each option separated by a comma or some other separator and use explode to separate them after pulling them out of the database. I don't know if this is sufficient for your application, but it's a thought.
    Marty H.

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    exbabylon, what can I say? That schema looks just beautiful!

    You have category -> product (one to many) and product -> option (one to many). So you have set up a relation(table) for the "many" entity that holds a foreign key to the primary key of the "one" entity.

    Eg, Foreign key Product.Product_Cat references primary key Product_Cat.ID

    PS: How many options can a "Lightweight Digging Tool" have? It reminds me of the Tom Waits song "Step Right Up"
    That's right, it filets, it chops, it dices, slices,
    Never stops, lasts a lifetime, mows your lawn
    And it mows your lawn and it picks up the kids from school
    It gets rid of unwanted facial hair, it gets rid of embarrassing age spots,
    It delivers a pizza, and it lengthens, and it strengthens
    And it finds that slipper that's been at large
    under the chaise lounge for several weeks
    And it plays a mean Rhythm Master,
    It makes excuses for unwanted lipstick on your collar
    And it's only a dollar, step right up, it's only a dollar, step right up

  4. #4
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok... now i feel really stupid... I have NEVER used a one-too-many or two-too-many relationship before.. and in truth, I don't even know how... that's why I thought I "may" have a problem with my idea... could you please humor stupid 'ol me and show me some code you may use to say, grab a product with with the product ID of, say 2? And have the options in a dropdown? What I was originally planning to do would have been a mess to say the least, about 20 while statements, and a bunch of database connections!

    Reply-PS:
    Actually it's for diameter of the specified product!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I feel really stupid most of the time - but I've got use to it

    OK - diameter. So the options are mutually exclusive (thus the drop down list). You could do it with one query that will join the tables and return a result set with a lot of redundant data, or do it with two seperate queries that return leaner result sets. Here I use two queries.

    I also assume that you are displaying the product identified by $id

    PHP Code:
    $sql "SELECT *
              FROM Product
              WHERE ID = 
    $id";

    $result mysql_query($sql);
    $product mysql_fetch_row($result)

    // print out the product details here (weight, price, etc)

    $sql "SELECT Value
                FROM Options
                WHERE Product_ID = 
    $id";

    $result mysql_query($sql);

    echo 
    "<select name='diameter'>";

    while (
    $option mysql_fetch_row($result) {
          echo 
    "<option>" $option["Value"] . "</option>";
    }

    echo 
    "</select>"
    Last edited by freakysid; Mar 16, 2001 at 18:57.

  6. #6
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes.. this i understand! I guess I was just not thinking when I asked... I thought mabey you had some great, advanced knowledge which could like cut coding in quarters.

    I thank you for your time, and insight!

    God Bless
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  7. #7
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I don't do mind-melds anymore. The insurance won't cover it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •