How would I go about duplicating records in a database with server connect (php)

How would I go about duplicating records in a database with server connect (php)

i have sc query on my page… with repeat region.

id id_to_duplicate name
1 4 name1
2 4 name2
3 4 name3
4 4 name4

and then with a server connect action looking for all id_to_duplicate (4) to copy and “duplicate” as (presuming the new id_to_duplicate would now be 5)

id id_to_duplicate name
5 5 name1
6 5 name2
7 5 name3
8 5 name4

What would be the best solution be to do this? Query the database… with a repeat? Check for the id_to_duplicate (4) … then copy the values and insert it again as a new record with id_to_duplicate (5)

Can anybody give me some ideas on the workflow …

Hello,

I cannot understand… Please give a few more details:
You have 1 table “NAMES” with fields(columns):

  • id,
  • id_to_dublicate
  • name1
  • name2
  • name3
  • name4

And you want to duplicate the records (let’s say Where id=1 ),inside the same table or into another table?
Which fields should be changed and based on which condition?

Probably you understand because you know what you have and what you want to do but I am sorry I got confused…

1 table

  • id,
  • id_to_dublicate
  • name

with result id id_to_duplicate name
1 4 name1
2 4 name2
3 4 name3
4 4 name4

Where id_to_duplicate=4

So i guess “query” repeat… where Where id_to_duplicate=4 and re-insert each one with the new id_to_duplicate=5

to produce
id id_to_duplicate name
5 5 name1
6 5 name2
7 5 name3
8 5 name4

There was a discussion here which might be helpful.

Edit: this might be helpful too.

1 Like

yeah…

  • DB_Query-A on id_to_duplicate=4
  • DB_Query-B pull last-larger id_to_duplicate
  • setvalue new_id_dupl = DB_Query-B.id_to_dublicate+1
  • repeat based on DB_Query-A
    — setvalue oldname from DB-QuartA
    — insert new_id_dupl, oldname

Hope you got it right my friend
I cannot send screenshot right now, not in wappler…
If you need help tell me

2 Likes

I would suggest to use a custom query and use insert into select query to duplicate in bulk.

1 Like

thanks @TomD … worked great… :slight_smile:

2 Likes

Glad it worked well @Mozzi, I use this a lot!

1 Like