• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple forum application  RSS feed

 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing a simple forum for homework assignment. I have come into one problem I need some help with.
When someone is replying to a post which is already in the database,
how do you process this reply to the database, what I mean is that - should is have the same topic_id as the orginial post, and if so how do I implement this as my topic_id column in database if primary key, auto_increment and doesn't allow duplicate entries of the same value.
Example:
Database columns
----------
topic_id (int, primary key, auto_inc)
title varchar
submitter varchar
message longtext
When someone clicks on the title of a topic, the relevant post related to this topic are displayed I wanted to do something like - select * from database where topic_id = "'+topic_id+"'. When someone the clicks on reply to this post -
I pass topic_id to processReply, where I add new post details, with same topic_id, however sql doesn't allow.
Im coding in jsp, jdbc?
Does anyone know how I should handle the reply to posts?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several solutions to your problem.
What you are looking at is a many to one relation between forum threads and forum posts.
A good way to implement that would be to have a THREAD table containing all forum threads, and a POSTING table containing forums posts (names up to you).
Each post has a THREADID field linking it to a thread, and a THREADSEQUENCE field to indicate its position inside that thread (though you could use the order in the database for that as well, it's probably cleaner to include a separate field here).
To have real threaded discussions, threads can themselves contain threads therefore should have a PARENTTHREAD field.
The tricky part of course is figuring out how to get all that information neatly read back in the correct order and pushed to the browser, but that's more housekeeping than anything else.
 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats just what I needed, thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!