Jump to content

Recommended Posts

Hello everyone.

 

I'd like to know how to duplicate a product through a php back-office.

 

That product consists of an ID in the "products" table of my DB. Then we have another table called "sub_products" that links its sub-products through a column named "product_id".

 

So I have product with ID "1000", and sub-products associated with it on another table with ID's "2021", "2022", "2023".

 

What's the routine I can use to duplicate both the product and its sub-products? I need to duplicate them because they fit 2 categories so I'm changing the category column during this duplicate.

 

Could really use some help. Thank you in advance!  :)

Link to comment
https://forums.phpfreaks.com/topic/215620-duplicate-products-within-mysql-db/
Share on other sites

I need to duplicate them because they fit 2 categories so I'm changing the category column during this duplicate.

 

You are taking the wrong approach. If a product and/or sub-product can belong to multiple categories then you should use an associative table to associate a product to one or many categories. If you duplicate products (for the same product) you are going to run into serious problems at some point. For example, if you need to manage inventory it would be very difficult if you are duplicating products.

 

Here is a quick example of the DB structure (with only the relevant fields for identifying categories)

 

Table: products

- prod_id

 

Table: categories

- cat_id

- cat_description

 

Table: Prod_cat

- prod_id

- cat_id

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.