DMXzone Server Connect Support Product Page

Answered

multi insert records

Asked 08 Mar 2018 10:44:55
1
has this question
08 Mar 2018 10:44:55 Carlin Chesnet posted:
I am looking to have the user enter the qty of records to add to the database and also a starting s/n.

I would like the user to be able to submit the request and then the records are created in the database.

example: 5 records with starting s/n 5659

database records to be made: 5659,5660,5661,5662,5663

this is an appconnect page with php serverconnect actions.

Replies

Replied 08 Mar 2018 10:59:38
08 Mar 2018 10:59:38 Greta Garberini replied:
Create an INTEGER field and make it auto-incremental. You could even use the ID field, starting with 5659.
Replied 08 Mar 2018 11:45:53
08 Mar 2018 11:45:53 Carlin Chesnet replied:
the s/n is not always incremental... the next entry could begin with a different number...

ie 1- 5656

then next user could be 2125 - 2123 ; 3256, 3159 ect....
Replied 08 Mar 2018 11:49:07
08 Mar 2018 11:49:07 Carlin Chesnet replied:
i was thinking of this method:

post qty of records & staring number

then use the repeater function [not sure how to have it run for '$post.qty' value]
then in each repeat have a insert task that will post the record with the sn + $index, so it will be sn 1 [1+0] then sn 2 [1+1] then sn 3 [1+2] ect until the repeat ends.
Replied 08 Mar 2018 11:51:55
08 Mar 2018 11:51:55 Teodor Kuduschiev replied:
Hello Carlin,
Check this tutorial please: www.dmxzone.com/go/32972/inserting-multiple-database-records

As for the serial number increment - yes, just use value + $index.
Replied 08 Mar 2018 13:02:07
08 Mar 2018 13:02:07 Carlin Chesnet replied:
Teodor,

I set the s/n to be $post.value + $index but the results were

93410 , 93411, 93412 ect when it should be: 9341, 9342, 9343 ect

also how to do i set the repeat expression to run only based on the $submit.qty value... I used {{$_POST}} and it ran the number of items passed in the post.
Replied 08 Mar 2018 13:03:41
08 Mar 2018 13:03:41 Carlin Chesnet replied:
I already made the form so do not need the builder... plus the video shows it will just make a form that has x number of duplicate fields.. and I do not want the user to have to enter the date over and over... all the submitted fields are the same for each insert except for the s/n as that should auto increase on each pass of the repeat...
Replied 08 Mar 2018 13:10:11
08 Mar 2018 13:10:11 Teodor Kuduschiev replied:
$post.value + $index must be $post.value.toNumber() + $index as form field values are always strings, and need to be converted to numbers.

I don't really understand what you mean for the form repeat?? The video shows what exactly you need in order to create a multi insert form.
Replied 08 Mar 2018 13:26:21
08 Mar 2018 13:26:21 Teodor Kuduschiev replied:
Ah, sorry i got your idea now.
All you need is a repeat step in the action file and put the insert step inside it.
The repeat expression is the value of the field, where the user enters how many records to insert.
This reply was removed on 3/8/2018 1:32:23 PM.
See the changelog
Replied 08 Mar 2018 13:37:17
08 Mar 2018 13:37:17 Carlin Chesnet replied:
ok, the number thing is working now. but the repeat only runs once. I am only passing a single item with a value greater then 1.
Replied 08 Mar 2018 13:39:56
08 Mar 2018 13:39:56 Carlin Chesnet replied:
got it to work. had to add .toNumber() to the expression.
Replied 08 Mar 2018 13:47:28
08 Mar 2018 13:47:28 Carlin Chesnet replied:
ok, the piece to my puzzle is this:

{{$_POST.snprefix + $_POST.serialnumber.toNumber() + $index}}

snprefix is a string ie, 2018- or A- ect...
Replied 08 Mar 2018 13:48:56
08 Mar 2018 13:48:56 Carlin Chesnet replied:
got it to work,

{{$_POST.snprefix}}{{$_POST.serialnumber.toNumber() + $index}}
Replied 08 Mar 2018 14:09:38
08 Mar 2018 14:09:38 Greta Garberini replied:
Thank you for sharing the result!

Reply to this topic