473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Efficient way to build a forum

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
11 3181
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
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
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
> 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
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
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
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
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
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: blockhead | last post by:
We are looking for someone to either complete a php forum program or create one for us. There isn't really anything that is available that suits our needs and we have specific wants. If you are...
16
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however...
5
by: Rudy | last post by:
Hello! does anybody know of any forum template in vb.net that I can work with. I would like to build a forum, but all that templates I found is in C#. In fact I'm finding alot of the cool...
7
by: Tom | last post by:
How can I make code not execute for a debug build, but do execute for a production build? I have code which prompts for an account and password when the program starts up. It is a pain to have to...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.