This is what I generally use.  Let me know if you need clarification.

<cffunction name="list_categories" returntype="string" output="No">
<cfargument name="myCatId" type="numeric" default="0" required="true">

<cfset var currQuery = "">
<cfset var returnString = "">

<cfquery name="currQuery" datasource="#request.dsn.name#"
username="#request.dsn.user#" password="#request.dsn.pass#">
SELECT catId, parentCatId, catName
FROM item_categories
WHERE parentId = #arguments.myCatId#
ORDER BY category
</cfquery>

<cfloop query="currQuery">
  <cfset returnString = returnString & catName & " &gt; ">
  <cfset returnString = returnString & list_categories( Val(currQuery.catId)
)>
</cfloop>

<cfreturn returnString>


</cffunction>

-----Original Message-----
From: Jake McKee [mailto:[EMAIL PROTECTED]
Sent: Monday, November 24, 2003 1:51 PM
To: CF-Talk
Subject: Recursion and Breadcrumbs

After searching high and low, I've found quite a few discussions about
using recursion to create breadcrumbs, and other nested "categorical"
info. It seems to be a pretty common question, and I would expect that
there is a common solution out there, but I can't seem to find one.

I'm trying to display:

Home > Cat > Sub Cat > Sub Sub Cat > .. Etc.

My DB table looks like :

Cat ID               CatName           ParentCatID

---------               -------------           -----------------

1                      CDs                  0

2                      Good CDs         1

3                      Bad CDs           1

4                      U2                    2

5                      Nsync               3

This would display:

Home > CDs > Good CDs > U2

Anyone have a straightforward code snippet for this?

Thanks!
Jake

--

My Blog -  <http://www.countersinkdg.com> www.countersinkdg.com


  _____  


[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to