Hi Ben,

You are overwriting the eventTitle var with each iteration through the loop. So this 
function is only going to return the last value. A function should only return one 
value at a time (unless you return a complex var type). You can stick the values in an 
array or list and return that instead... 

Phillip

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Ben Densmore
Sent: Tuesday, July 13, 2004 11:45 AM
To: [EMAIL PROTECTED]
Subject: [CFCDev] Return values from a loop


I'm reading in an XML file and trying to output some of the data. If I
do a loop in the cfc and try to output it to a page I am only getting
one value returned instead of all 7. I'm guessing because my cfreturn is
outside of the loop but I can't seem to get it to display. The code in
my cfc looks like:

<cfcomponent>
        <cffunction access="public" name="readAll" output="false"
returntype="string">
                <cffile action="read"
file="C:\cfusionMX\wwwroot\SparkEventsCalendar_loadXml.xml"
variable="event">
        <cfset variables.calEvents = XmlParse(event)>
          <cfloop from="1"
to="#ArrayLen(variables.calEvents.events.XmlChildren)#"
index="evntTitle">
                  <cfset eventTitle =
variables.calEvents.events.event[evntTitle].XmlAttributes.title />
                  </cfloop>
                <cfreturn eventTitle />
        </cffunction>
</cfcomponent>

Then I'm doing:
<cfset variables.events = createObject("component", "events").readAll()
/>


<cfoutput>#variables.events#</cfoutput>

Thanks,
Ben
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to