Skip to main content
Inspiring
October 14, 2008
Question

Inserting multiple lists

  • October 14, 2008
  • 1 reply
  • 292 views
I have a form with checkboxes, all the same name. The output is a list separated by commas. So when I insert into my table, I do soemthing like this :

<cfloop list="#form.error_id#" index="error_id_value">
<cfquery name="qryInsert_Error_Log" datasource="dbName">
Insert into UnReceivables_Error_Log
(error_transaction_id,
error_id,
ref_number,
error_status)

values
('#error_txn_id#',
'#error_id_value#',
'#ref_number#',
'active')
</cfquery>

Now I have a form that uses javascript to add additional rows to the form. Each row contains a part number, qty, and cost. If I genearate and add five rows, and when I submit, I use cfoutput to display the values and they come out as pn1,pn2,pn3,pn4,pn5 and qty1,qty2,qty3,qty4,qty5 and cost1,cost2,cost3,cost4,cost5.

What do I have to do to insert each list/value record into a table, so that they all correspond to one anohter ?
For example, the first row in the table, after insert, should be pn1, qty1, and cost 1. The second row should be pn2, qty2, and cost2, etc.

Thanks for any help.
    This topic has been closed for replies.

    1 reply

    Inspiring
    October 14, 2008
    Are you talking about the one form or two ?

    Basically when the js add a row to the for it should also add one to a row count field (hidden)

    You would then loop through this row count to do the insert.

    With the supplied code, lets assume the form fields the js creates are called
    error_txn_id and ref_number with a number on the end (1, 2, ect)

    The see example code...

    Ken
    trojnfnAuthor
    Inspiring
    October 15, 2008
    I am only talking about one form.

    The javascript button will add new rows, consisting of three fileds, pn, qty and cost. The error file is just an example that I used previously for input of one list only. With the addtional rows, it is producing three lists that I need to submit and that is what I dont know how to do. I will try and use your sample code with the index. I think that is what I am missing, since that will tie all the records together.