Original call would look something like this, where entryID is all you need to
start with:
<cfset myReplyTreeQry = getChildren(url.entryID, request.datasource)>
This would create a query result called myReplyTreeQry with the following
columns:
entryID
replyID (of each reply)
parentReplyID (of each reply, not really needed, but good for debugging)
level (of each reply, to help in indenting as you output them)
Obviously, more columns would need to be added to show all the actual Reply
information, but this works for the recursive structure.
<cffunction name="getChildren" returntype="query" output="no">
<cfargument name="entryID" type="string" required="yes">
<cfargument name="datasource" type="string" required="yes">
<cfargument name="parentReplyID" type="string" required="no" default="">
<cfargument name="rtnQuery" type="query" required="no">
<cfargument name="levelCtr" type="numeric" required="no" default="0">
<cfset var ds = arguments.datasource>
<cfset var rtn = "">
<cfset var childQry = "">
<cfset var level = arguments.levelCtr>
<cfif not structKeyExists(arguments, "rtnQuery")>
<cfset rtn = queryNew("entryID, replyID, parentReplyID, level")>
<cfelse>
<cfset rtn = arguments.rtnQuery>
</cfif>
<cfquery datasource="#ds#" name="childQry>
SELECT e.entryID,
r.replyID,
r.parentReplyID
FROM entries e LEFT OUTER JOIN
replies r ON e.entryID = r.entryID
WHERE e.entryID = <cfqueryparam cfsqltype="CF_SQL_VARCHAR"
value="#arguments.entryID#">
AND r.parentReplyID = <cfquerparam
cfsqltype="CF_SQL_VARCHAR" value="#arguments.parentReplyID#">
</cfquery>
<cfif childQry.recordCount>
<cfset level = level + 1>
<cfoutput query="childQry">
<cfset queryAddRow(rtn)>
<cfset querySetCell(rtn, "entryID", entryID)>
<cfset querySetCell(rtn, "replyID", replyID)>
<cfset querySetCell(rtn, "parentReplyID",
parentReplyID)>
<cfset querySetCell(rtn, "level", level)>
<!--- now call this function recursively --->
<cfset rtn = getChildren(
arguments.entryID,
ds,
replyID,
duplicate(rtn),
level
)>
</cfoutput>
</cfif>
<cfreturn rtn>
</cffunction>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314872
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4