This is not very good but givens the idea. You shouldnt really use the
function for output... a two dimensional jagged array would be nicer to hold
the data so you can seperate the database logic from the display.
The trick to calling functions recursivly in CF is the scoping of your
variables. The 'var' keyword will ensure that the variable is unique to that
function.
<CFFUNCTION NAME="printTree" RETURNS="VOID" OUTPUT="YES">
<ARGUMENT name="id" TYPE="numeric" DEFAULT="0" required="no">
<CFSET var getThem = "">
<CFQUERY NAME="getThem" DATASOURCE="myDat">
SELECT categoryID, categoryName
FROM tblCategory
WHERE parentID = #arguments.id#
</CFQUERY>
<CFOUTPUT QUERY="getThem">
<CFIF arguments.id neq 0>/</CFIF>
#CategoryName#<BR>
<CFSET printTree(#arguments.id#)>
</CFOUTPUT>
<CFRETURN>
</CFFUNCTION>
then in you body
<CFSET printTree()>
PS: keep in mind this is off the top of my head so its probably wrong :P
Gunther
-----Original Message-----
From: Terry Hogan [mailto:[EMAIL PROTECTED]
Sent: Friday, 30 May 2003 12:25 PM
To: CF-Talk
Subject: OT: SQL--Recursive Query Question
I have this table Structure
tblCategory
-----------
CategoryID
ParentID
Level
CategoryName
with this data
CategoryID ParentID Level CategoryName
---------- -------- ----- ------------
1 0 1 Animals
2 1 2 Dogs
3 2 3 GermanShepard
4 1 2 Cats
5 4 3 Siamese
I'd like to put together a query where I could output something like:
Animals
Animals/Dogs
Animals/Dogs/GermanShepard
Animals/Cats
Animals/Cats/Siamese
I only plan on going 3 levels deep.
Thanks for any help.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics.
http://www.fusionauthority.com/signup.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4