I was not sure if you needed to invoke this as a web service or simply
an object, so I wrote up each. This makes one call for each 'class'
that needs to be created. If you wanted to reduce hits on your
database, I would refactor this to take an array of structures of
'classes' as an argument and then loop over the array and do the inserts
from that.
<!--- OBJECT CALL --->
<cfset myObj = createObject('component', 'path.to.obj') />
<cfloop from="1" to="#form.totalPERSONS#" index="idx">
<cfset myObj.createEnrollment(evaluate('form.enrID#idx#'),
evaluate('form.part_class#idx#')) />
</cfloop>
<!--- WEBSERVICE CALL --->
<cfloop from="1" to="#form.totalPERSONS#" index="idx">
<cfinvoke webservice="myWEBSERVICE" method="createEnrollment"
returnvariable="newID">
<cfinvokeargument name="ernID"
value="#evaluate('form.enrID#idx#')#" />
<cfinvokeargument name="class"
value="#evaluate('form.part_class#idx#')#" />
</cfinvoke>
</cfloop>
<!--- FUNCTION --->
<cffunction name="createEnrollment" access="remote"
returntype="numeric">
<cfargument name="ernID" required="true" type="numeric">
<cfargument name="class" required="true" type="string">
<cfset var qWrite = "" />
<cfquery name="qWrite" datasource="yourdsn">
INSERT INTO participants (
enrID,
part_class )
VALUES (
<cfqueryparam cfsqltype="cf_sql_integer"
value="#arguments.ernID#">,
<cfqueryparam cfsqltype="cf_sql_varchar"
value="#arguments.class#">
)
</cfquery>
<cfreturn qWrite.newID>
</cffunction>
HTH,
Rich Kroll
> -----Original Message-----
> From: Les Mizzell [mailto:[EMAIL PROTECTED]
> Sent: Thursday, December 14, 2006 9:36 PM
> To: CF-Talk
> Subject: cffunction with a loop inside - need some advice
>
> OK - before I tried turning this particular problem into a service, I
> had a simple query like this, which works (examples simplified for
> clarity, whatever that is!):
>
> <cfloop from="1" to="#form.totalPERSONS#" index="idx">
> <cfquery name="WRITE_ENROLL">
> INSERT INTO participants (
> enrID,
> part_class )
> VALUES (
> #evaluate("form.enrID#idx#")#,
> '#evaluate("form.part_class#idx#")#' )
> </cfquery>
> </cfloop>
>
>
> The function to handle this once converted is failing with 'Can't
> generate stub....blan, blah.... so I've got a syntax problem or just
> simply don't know what I'm doing trying to translate the above.
>
> Here's what I've got:
>
> To invoke the beast:
>
> <cfinvoke webservice="myWEBSERVICE"
> method="ENROLLMENTS"
> WStotalPERSONS="#form.totalPERSONS#"
> <cfloop from="1" to="#form.totalPERSONS#" index="idx">
> WSenrID#idx#="#evaluate("form.enrID#idx#")#"
> WSpart_class#idx#="#evaluate("form.part_class#idx#")#"
> </cfloop>
>
> >
>
>
> And here's the function:
>
> <cffunction name="ENROLLMENT_TWO"
> access="remote"
> returntype="query" >
>
> <cfargument name="WStotalPERSONS" type="numeric" />
> <cfloop from="1" to="#arguments.WStotalPERSONS#" index="idx">
> <cfargument name="WSenrID#idx#" type="string" />
> <cfargument name="WSpart_class#idx#" type="string" />
> </cfloop>
>
<cfloop
> from="1" to="#WStotalPERSONS#" index="idx">
> <cfquery name="WRITE_ENROLL">
> INSERT INTO participants (
> enrID,
> part_class )
> VALUES (
> WSenrID#idx#,
> 'WSpart_class#idx#")#' )
> </cfquery>
>
> </cfloop>
>
>
>
>
> I probably need to rethink the way this particular function has to
work,
> but I desperately need some pointers please!
>
> Thanks,
>
>
> Les
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:264107
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4