Jump to content

How to duplicate a database entry?


Julian

Recommended Posts

Hi guys

What I want to do is this:

I have a form which insert the info into the database.  Then I have a result page where I can see the info on the database.  I put a edit button and delete button in order to admin the database.  That works great.  Here's the thing:  I want to add a duplicate button after the edit and delete, so, the user can duplicate the info on the database entry and edit only the part he needs and keep the original.  It's like a "save as" option.

Any help help will be appreciated.
Link to comment
https://forums.phpfreaks.com/topic/25755-how-to-duplicate-a-database-entry/
Share on other sites

Hi,

I would do this by adding an aditional coloum into your database table, for the pourpous of identifying each entrie, and seting this to automaticaly incrament every time a new row is added. (what database type are you using?)  This garanties you a unique id number for each entrie.  you can then add a new row into the database containing the data you have already have pulled out, the only diffrence being the id it is assgned.  Your can then get this new ID number by serching for SELECT id_coloums_name FROM table_name WHERE coloum_of_origional_data ILIKE 'data_on_page' (example is pgSQL but simialar format for most).  This will of course give you more then one option, but you can ignor the one of the origional data. (store this in a variable when you make your first poll for the origional data).  Then the changes the made can be updated using this ID number as a refrance point in the table. . . .

In a less long winded way:
1)  re-insert the data, using auto_incriment id.
2)  get new id number
3)  Update changes using the new id number

The only problem with this is that if you have a large table adding to it will make poll's slowly slower.  Can get round this by having a second table to store the altered dater/'save as' versions in.

Hope i havent discribed this to much like mud!  There may well be better ways.

Archived

This topic is now archived and is closed to further replies.

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