Kyrus Posted October 11, 2010 Share Posted October 11, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/215620-duplicate-products-within-mysql-db/ Share on other sites More sharing options...
BlueSkyIS Posted October 11, 2010 Share Posted October 11, 2010 select the record to be copied, load it's values into variables, then insert a new record with those variables. it should be the same as when you insert a new product, but you're just selecting an existing product to get the pertinent data. Quote Link to comment https://forums.phpfreaks.com/topic/215620-duplicate-products-within-mysql-db/#findComment-1121097 Share on other sites More sharing options...
Psycho Posted October 11, 2010 Share Posted October 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/215620-duplicate-products-within-mysql-db/#findComment-1121121 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.