Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting Multiple rows!!

Status
Not open for further replies.

hummer

Technical User
Sep 20, 2001
1
CA
Any one who helps in getting coldFusion tag to insert multiple rows at one time?


Thanks.
 
You could just use <cfloop> to execute a <cfquery> tag several times to insert several rows of the same data. I'm guessing your problem isn't this simple so if you could give me an idea of what data you're looking to insert several times and how it's formatted, I could give you a better answer.

GJ
 


Thanks to your prompt reaction,


To be more specific, i have created the form page with simple html and added &quot;form1#CurrentRow#&quot; to the name

<input type=&quot;Text&quot; name=&quot;form1#CurrentRow#&quot; size=&quot;8&quot; maxlength=&quot;20&quot;>

and the action page looks the following. But it doesnt work.




<CFQUERY NAME=&quot;GetWoord&quot; datasource=&quot;mydsn&quot; dbtype=&quot;ODBC&quot;>
SELECT *
FROM table
</CFQUERY>

<!--- Declare variable rec to sort and get the last record count --->

<cfset rec = Listlast(listsort(valuelist(GetWoord.nr), &quot;numeric&quot;, &quot;asc&quot;))>

<!--- Run loop: one for every row outputed earlier --->

<cfloop index=&quot;i&quot; from=&quot;#rec#&quot; to=&quot;#form.RecordCount#&quot;>



<cfset locfild1 = &quot;form.fild1&quot; & i>
<cfset locfild2 = &quot;form.fild2&quot; & i>
<cfset locfild3 = &quot;form.fild3&quot; & i>
<cfset locfild4 = &quot;form.fild4&quot; & i>
..


<!--- All dynamic form variables are evaluated here . --->

<cfquery name=&quot;getwoord#i#&quot; datasource=&quot;mydsn&quot;>
INSERT INTO table
(fild1, fild2, fild3, fild4,... )
VALUES
('#Evaluate(locfild1)#', '#Evaluate(locfild2)#', '#Evaluate(locfild3)#',...)
</cfquery>

<!--- Loop to next row --->

</cfloop>


<!--- use CFLOCATION to return to beheerform.cfm --->

<CFLOCATION URL=&quot;mainform.cfm&quot; addtoken=&quot;No&quot;>



 
One problem I see is that #rec# will contain the largest value of the field &quot;nr&quot;. If this corresponds to record numbers, you are basicly setting #rec# to the number of records in your query. In your <cfloop>, you start from #rec# and go to #form.RecordCount# which I assume will be the same number. I'm not sure what you're coding but I think this might work.

<cfloop query=&quot;GetWoord&quot;>
<cfquery name=&quot;getwoord#i#&quot; datasource=&quot;mydsn&quot;>
INSERT INTO table
(fild1, fild2, fild3, fild4,... )
VALUES
('#Evaluate(&quot;form.fild1#GetWoord.currentRow#&quot;)#', '#evaluate(&quot;form.fild2#GetWoord.currentRow#&quot;)#',
'#Evaluate(&quot;form.fild3#GetWoord.currentRow#&quot;)#',...)
</cfquery>
</cfloop>

Hope this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top