By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

Efficient way to build a forum

P: n/a
Hi there.

This is not really a PHP-question, but I think you guys should know that ;-)

I am building a forum for a friend of mine using Borland Delphi's
WebServices. It will be a rather small one, for just about ten people, older
postings will be deleted after 3 months.

From the Delphi-side, I know how to do it but I'm not sure about how to keep
the hierachical structure when saving the threads. Right now, I would store
each post (and therefore each reply) in a seperate .txt on the server, write
it's ID and timestamp into and remember it's child-post(s) (if it has one).

There has to be a better way. So could anyone tell me how this task is
accomplished in PHP? Please don't post any PHP-source, I just want to know
how it is usually done and I'll try to do that using Delphi.

Thanks in advance

Mike
Jul 17 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On Thu, 20 Nov 2003 09:33:33 +0100, "Michael Trojanek"
<tr*@adv.magwien.gv.at> wrote:
I am building a forum for a friend of mine using Borland Delphi's
WebServices. It will be a rather small one, for just about ten people, older
postings will be deleted after 3 months.

From the Delphi-side, I know how to do it but I'm not sure about how to keep
the hierachical structure when saving the threads. Right now, I would store
each post (and therefore each reply) in a seperate .txt on the server, write
it's ID and timestamp into and remember it's child-post(s) (if it has one).

There has to be a better way. So could anyone tell me how this task is
accomplished in PHP? Please don't post any PHP-source, I just want to know
how it is usually done and I'll try to do that using Delphi.


In PHP it's usually database driven.

The easiest way is to have a topics table and a posts table. Each row
in the posts table may point to a parent post, or to itself (if it's
the root post), and the topics table is used to stage "last post",
"num replies" etc to avoid overhead when listing topics.

You would normally put the message bodies in a seperate table too.

You can build on top of that of course with topic sections etc, but
the above explains the basics.
kafooey
- ka*****@nospam.yahoo.co.uk
- http://www.pluggedout.com/blog
Jul 17 '05 #2

P: n/a
Each answer has the id of its parent.
id = 0 for heads of threads (no parent).

Recursive functions can find their ways in the messages tree very easily.

Better use a database than flat files to store the messages.

Nicolas

Jul 17 '05 #3

P: n/a
Nicolas wrote:
Each answer has the id of its parent.
id = 0 for heads of threads (no parent).
I would also include a thread id to select all related messages easily.
Recursive functions can find their ways in the messages tree very easily.

Better use a database than flat files to store the messages.
Definitely
Nicolas


Jul 17 '05 #4

P: n/a
> I would also include a thread id to select all related messages easily.

Right : I had to add it to my first forum because otherwise it was a real
pain to get all messages from one thread.

Nicolas
Jul 17 '05 #5

P: n/a
On 2003-11-21, Nicolas <fa****@adresse.com> wrote:
I would also include a thread id to select all related messages easily.


Right : I had to add it to my first forum because otherwise it was a real
pain to get all messages from one thread.


There is no need for that.

The first message in a thread, gets parent_id=0

Now selecting all the messages in this thread:

function show_message($messageid) {
// show message
select message_id from messages where parent_id=$messageid
foreach(message_id) {
show_message($message_id)
}
}

--
verum ipsum factum
Jul 17 '05 #6

P: n/a
Tim Van Wassenhove wrote:
On 2003-11-21, Nicolas <fa****@adresse.com> wrote:
I would also include a thread id to select all related messages easily.


Right : I had to add it to my first forum because otherwise it was a real
pain to get all messages from one thread.

There is no need for that.

The first message in a thread, gets parent_id=0

Now selecting all the messages in this thread:

function show_message($messageid) {
// show message
select message_id from messages where parent_id=$messageid
foreach(message_id) {
show_message($message_id)
}
}


If you are using a flat forum then this would be fine. If, however you
are using a tiered indented forum then that will only give you replies
to the original post. You would need a recursive routine to list replies
to each reply. Lots and lots of SQL queries.
Jul 17 '05 #7

P: n/a
On 2003-11-21, Kevin Thorpe <ke***@pricetrak.com> wrote:
Tim Van Wassenhove wrote:
On 2003-11-21, Nicolas <fa****@adresse.com> wrote:
I would also include a thread id to select all related messages easily.

Right : I had to add it to my first forum because otherwise it was a real
pain to get all messages from one thread.

There is no need for that.

The first message in a thread, gets parent_id=0

Now selecting all the messages in this thread:

function show_message($messageid) {
// show message
select message_id from messages where parent_id=$messageid
foreach(message_id) {
show_message($message_id)
}
}


If you are using a flat forum then this would be fine. If, however you
are using a tiered indented forum then that will only give you replies
to the original post. You would need a recursive routine to list replies
to each reply. Lots and lots of SQL queries.


Err, what am i missing? my pseudo function does have recursion.

--
verum ipsum factum
Jul 17 '05 #8

P: n/a
Tim Van Wassenhove wrote:
On 2003-11-21, Kevin Thorpe <ke***@pricetrak.com> wrote:
Tim Van Wassenhove wrote:
On 2003-11-21, Nicolas <fa****@adresse.com> wrote:
>I would also include a thread id to select all related messages easily.

Right : I had to add it to my first forum because otherwise it was a real
pain to get all messages from one thread.
There is no need for that.

The first message in a thread, gets parent_id=0

Now selecting all the messages in this thread:

function show_message($messageid) {
// show message
select message_id from messages where parent_id=$messageid
foreach(message_id) {
show_message($message_id)
}
}


If you are using a flat forum then this would be fine. If, however you
are using a tiered indented forum then that will only give you replies
to the original post. You would need a recursive routine to list replies
to each reply. Lots and lots of SQL queries.

Err, what am i missing? my pseudo function does have recursion.

Ah, sorry... it is Friday afternoon here.

Doing that though does hit the SQL server a lot more than selecting all
messages for a thread.

Jul 17 '05 #9

P: n/a
> There is no need for that.

I agree you can do without, but is it better ?

It is always a problem when working with trees which are saved in databases
: put the load on the SQL server or on PHP (or on both). Sometimes it is not
a bad idea to deal with a subset of the tree with PHP rather than overload
the SQL server.

Nicolas
Jul 17 '05 #10

P: n/a
Tim Van Wassenhove, obviously a huge fan of Bruce Campbell, wrote:

function show_message($messageid) {
// show message
select message_id from messages where parent_id=$messageid
foreach(message_id) {
show_message($message_id)
}
}


Jesus christ, I'm glad I'm not sharing an sql server with you.

/joe
--
Jeff Jones's load of ducketts is terrific.
Jul 17 '05 #11

P: n/a
Kevin Thorpe wrote:
If you are using a flat forum then this would be fine. If, however you
are using a tiered indented forum then that will only give you replies
to the original post. You would need a recursive routine to list replies
to each reply. Lots and lots of SQL queries.

Err, what am i missing? my pseudo function does have recursion.

Ah, sorry... it is Friday afternoon here.

Doing that though does hit the SQL server a lot more than selecting all
messages for a thread.

You can do both things. Have a thread ID, and have a reference, that
being the message ID of the message it replies to. Use the thread ID to
pull all the messages from the database in one query, putting then in an
array or something. Then use the references and timestamps to sort into
a tree structure.

Brian Rodenborn
Jul 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.