If you're "tree-ing" the recordset, I assume that you have a itemID/parentID
field coupling?  Here's the basic algorithm that I use to perform such a
convertion:

<cffunction name="makeTree">
  <cfargument name="rs" />
  <cfargument name="parentID" default="" />
  <cfargument name="level" default="0" />
  <cfloop query="rs">
    <cfif rs.parentID EQ parentID>
      <cfoutput>#repeatString("&nbsp; ", level)##rs.name#<br /></cfoutput>
      <cfset makeTree(rs, itemID, level + 1) />
    </cfif>
  </cfloop>
</cffunction>

Keep in mind that this isn't particularly efficient (even with optimization)
and that you should try to cache the generated tree in some form or another,
rather than regenerating it every request.  If you need to generate it every
request, then you're probably better of using a different storage mechanism
(the Nested Set Model, is one).

Cheers,
barneyb

Cheers
barneyb

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Monday, May 17, 2004 1:12 PM
> To: CF-Talk
> Subject: Using recursion with query results
>
> I'm trying to build a recursive routine that will go through my query
> results and display them in a tree structure.  There are four
> fields in each
> row of my results.  Is it possible for me to pass an entire
> row of my query
> results to a custom tag?  If so, when I come back out of my recursive
> routine, will CF "know" that that row has been processed?  Or
> is it best for
> me to throw all my query results into a structure then run
> the recursive
> routine?
>
> I've done this in ASP, but I'm at a loss in ColdFusion.  I
> know this should
> be easy, but....
>
> Nancy P. Tracy
> Electrical Design and Web Development
> GE Global Controls Services
> 3800 N. Wilson Ave.
> Loveland, CO 80538
> 970.461.5273
>
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to