Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cascading/stepped forum

Status
Not open for further replies.

ahc142a

Technical User
Aug 4, 2001
30
0
0
GB
I have managed to create a forum, but i have a problem in that i am trying to get a stepped affect.
It is stepped at the moment, but all parent replies & sub-replies etc. tend to get grouped together. i.e. a child reply doesn't necessarily appear below its parent, even though it maybe indented.

The relevant fields in the table are as follows:

commentID(a unique identifier)
replyflag( to identify what level of reply it is
& therefore how much to indent that comment)
parentID ( which refers to the commentID of the very
top level comment)
realparentID ( which refers to the commentID of the
real parent of a comment)


Any suggestions as to how i can get a stepped affect when i make a call to the table.

At the moment i am doing something like this:

<!---commentIDArray contains all the top level commentID's, i.e. root comment--->

<cfloop from=1 to= ArrayLen(commentIDArray) index=i>
<cfquery name=baba datasource = blacksheep>
SELECT *
FROM commentstable
where parentID = '#commentIDArray#' AND replyflag >1;
</cfquery>
</cfloop>

And to top it all of all the above is within a <cfoutput> already.
Thanx in advance.
 
No sure how you would do this i guess you could use a database
to identify parent and child posts maybe you can use cftree or a javascript tree to display the tree.


HTH
 
I don't know that there's a way to setup your query to retrieve the records ordered the way you want since you're dealing with an infinite number of possible levels.

I would create a custom tag that can be called recursively to dig down through all potential levels. I'll outline the basics of it and if you try it and have trouble, just let me know.

You basically want to have a custom tag that will take a commentID and return a query of all subs. You could call it &quot;getReplies&quot; and call it like this.
<cf_getReplies return=&quot;q1&quot; parentID=#commentIDArray#>

Inside getReplies.cfm, you basically query to get the sub comments, and then loop through these, and get their subcomments. This custom tag would call itself which does the recursion and gives you the entire comment group in order.

Here's a start of how getReplies.cfm (custom tag) would look:

<cfquery name=&quot;innerQuery&quot; datasource = blacksheep>
SELECT commentID FROM commentstable
where realparentID = '#attributes.parentID#' AND replyflag >1;
</cfquery>

<cfset tempQ=queryNew(&quot;commentID&quot;)>

<cfloop query=&quot;innerQuery&quot;>
<cfset queryAddRow(tempQ)>
<cfset querySetCell(tempQ,&quot;commentID&quot;,innerQuery.commentID)>
<cf_getReplies return=&quot;q1&quot; parentID=#innerQuery.commentID#>
<cfloop query=&quot;q1&quot;>
<cfset queryAddRow(tempQ)>
<cfset querySetCell(tempQ,&quot;commentID&quot;,q1.commentID)>
</cfloop>
</cfloop>

<cfset &quot;caller.#return#&quot;=tempQ>

...end of custom tag...

In this example, the query you get back from the custom tag just returns the commentid but you can add additional querySetCell statements to add other fields such as the replyFlag.

Good luck, recursion isn't easy :)
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top