Threading is pretty easy.
Give ever message an ID, when someclick 'reply to this msg' their new message is created with a new ID and then have another field called replyTo and give it the ID of the msg they replied to.
When you go to show the msgs you simply have a function that shows the msg then shows any msgs with ReplyTo equaling to the msgs ID then for each new msgs run the function again against that ID.
for example
show_msg(10,0); // show msg with ID 10
function show_msg(id,depth) {
// do database stuff up here
print msginfo; //show whatever
//author body, date..
// then do a search for any msg that have the ReplyTo==id
//for each found run show_msg(msg_id);
show_msg(msg_id,new_depth);
}
the depth cariable is for what level the msg is in
so when you show the first message it has a depth of 0. messages under that are 1 and under one is 2. so for example
1
2
2
3
2
2
That is just for making indented type threading. helps out a lot.