Reply to topic
Multiple record insert
shill


Joined: 17 Feb 2007
Posts: 6
Location: Knoxville, TN
Reply with quote
I am stumped with some code would appreciate any suggestions.

I have a form used for requesting documents and it contains about 5 text fields and six checkboxes. For every box that is checked, I need to insert a new row in a table which has a requestID, requestTypeID and documentID. My plan was to loop over the form fields to get the IDs and do the insert via CFLOOP, but I am not having any luck.

Code:

<cfloop list="#form.fieldnames#" index="i">
<cfif isDefined("#i#")>
<cfquery name="insDocRequestData" datasource="mydatasource">
INSERT INTO requestList  (requestID, requestTypeID, docID)
VALUES (#insRequest.NewRequestID#, <!---ID coming from another insert--->
#Evaluate(form.requestTypeID)#, #Evaluate(form.docID)#)
</cfquery>
</cfif>   
</cfloop>


Any suggestions? Recommendations and code corrections are welcomed!
Re: Multiple record insert
Jason101
Forum Regular

Joined: 14 Mar 2006
Posts: 550
Location: Harrisburg, PA
Reply with quote
If you name all the check boxes the same (but with different values), the values will be put into that variable as a list. So all you need to do is loop over the list to do your inserts.

Example:

The form field passed is called DocumentIDs and that Form variable now contains : 10,22,19,15

So you'll loop over that field:


<cfloop list="#Form.DocumentIDs#" index="item">
<cfquery name="insDocRequestData" datasource="mydatasource">
INSERT INTO requestList (requestID, requestTypeID, docID)
VALUES (#insRequest.NewRequestID#, <!---ID coming from another insert--->
#Evaluate(form.requestTypeID)#, #item#)
</cfquery>
</cfloop>

Is this what you are trying to do?
shill


Joined: 17 Feb 2007
Posts: 6
Location: Knoxville, TN
Reply with quote
Hi Jason,

Yep, that's it! Thanks for your help. Much appreciated.
Multiple record insert
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic