Click to See Complete Forum and Search --> : Designing a threaded forum in ASP


Mike Caverly
07-25-2003, 07:35 PM
I have a fairly basic grasp of ASP and Access development and I want to create a threaded forum, by having a field in the table which stores the messages, for referring back to a previous message. When it comes to displaying the messages it seems like I need to open all 'root' messages (i.e. messages that have no refering message, then cycle through each of these records in turn, looking for further referals, and so on.

My question concerns whether this is the right way to go about it. Does it mean opening a new recordset for each message in the table, and do I have to close and destroy each one before opening the next?

The reason I want to do this is mostly in order to learn how to do it. It's part of a larger project that involves inter-related (threaded) content, so I want to start off on the right footing and will be gratefull for any advice.

Mike Caverly
07-26-2003, 04:35 AM
wouldn't this type of table structure be for a 'flat' forum - like this one for instance? The type of forum I have in mind is more like a newsreader with multiple branching threads, so in both the scenarios you describe [ThreadId] would correspond to a previous [PostId]. So in the 2 table approach it would be more like:

Table 1:
--------- -------- ----------------
| ForumId | PostId | (other fields) |
--------- -------- ----------------
PostId is an autonumber field

Table 2:
-------------- ------------- ----------------
| ParentPostId | ChildPostId | (Other fields) |
-------------- ------------- ----------------
both Parent- and Child- PostId's are foreign keys relating to PostId in the 1st table.

I've tried this and it works and isn't to hard to code - if I only want to display one message at a time along with a list of its 'children'. But I want to display all message headers in a type of tree structure, in one frame on a page, with another for displaying the body of the message header selected. I can see a way of doing this by looping through the records, checking each one for children, then checking those children for children and so on, but it must be quite labour-intensive on the server which is why I was wondering if there's a better way.

I posted a differnt problem about the same forum on my ISP's message boards and was told use an existing readily available PHP script and to stop trying to reinvent the wheel. I'm not - I'm trying to build my own wheel that I can then build a car around

Mike Caverly
07-29-2003, 02:44 PM
Thankyou for the response, and I appologise to all users for calling this a flat forum, it was just to illustrate the contrast with what I wish to do.

Actually I was getting through too many cups of coffee and too many cigarettes trying to get my head around the recursive code to generate a message tree so for the time being I'm going to settle for studying and customizing 'existing readily available' script. if anyone else is interested there's an article and source code available at http://www.asp101.com/resources/aspforum_2.asp