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
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.
Link to comment
Share on other sites

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.