> -----Original Message-----
> From: Chris Martin [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, May 03, 2001 11:13 AM
> To: CF-Talk
> Subject: Finding the last item in a loop
> 
> 
> IS it possible to find the last item in a loop?
> 
> Right now I have this:
> 
> <cfloop query="qry_show_event_sponsors">
>       #EventSponserName#,
> </cfloop>
> 
> Is it possible to check if the #EventSponsorName#  is the last item in the
> record set, and then not display the comma?  I.E.
> 
> <cfloop query="qry_show_event_sponsors">
>       #EventSponserName#<cfif something>,</cfif>
> </cfloop>

Sure... you can do this instead:

<!--- Start --->

<cfloop from="1" to="#qry_show_event_sponsors.RecordCount#" index="ThisRow">
        <cfoutput>
        #qry_show_event_sponsors.EventSponsorName[ThisRow]#
        #IIF(ThisRow LT qry_show_event_sponsors.RecordCount,DE(','),DE('')#
        </cfoutput>
</cfloop>

<!--- End --->

ORRRRRR...

You could do it a bit simpler, using the ValueList() function:

<!--- Start --->

<cfset SponsorList = ValueList(qry_show_event_sponsors.EventSponsorName)>

<cfoutput>#SponsorList#</cfoutput>
        
        
<!--- End --->

Since you didn't have a <br> tag in there after each item in your loop, I assume you 
wanted a list like:

Sponsor1,Sponsor2,Sponsor3

If you wanted a <br> in there, you could use a conditional like in the first example 
to either display or not display it.

....and others will come up with different or better ways, I'm sure!


-Andy


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to