473,385 Members | 1,333 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,385 software developers and data experts.

Advice on forum to built

Hi there,

I'm going to build a simple forum in mySQL.
I've thought about it for a while now, but still can't figure it
out completely:

If i have say 5 main categories,
One has 5 sub-categories.
Each sub category consists of individual threads.
Wich each has the possibility to be commented.

The question concerns the thread & comments part.
My first idea was to create one table Threads, and one
Comments.
The Threads-table would have the original post, starting a thread,
and the Comments table would have the comment, and the id of
the thread it belongs to. (so all comments there are in the whole
forum)

Now i thought of the following:
I could create a new table for each thread to save it's comments in.
And call it e.g. 'Comments_4576', (belonging to thread 4576)

Pro is a lot faster to load, delete etc. but contra is more difficult
to
count cross-tables and everything.

What could i do best?

Greetings.

Jan 3 '06 #1
6 1393
frizzle wrote:
Hi there,

I'm going to build a simple forum in mySQL.
I've thought about it for a while now, but still can't figure it
out completely:

If i have say 5 main categories,
One has 5 sub-categories.
Each sub category consists of individual threads.
Wich each has the possibility to be commented.

The question concerns the thread & comments part.
My first idea was to create one table Threads, and one
Comments.
The Threads-table would have the original post, starting a thread,
and the Comments table would have the comment, and the id of
the thread it belongs to. (so all comments there are in the whole
forum)

Now i thought of the following:
I could create a new table for each thread to save it's comments in.
And call it e.g. 'Comments_4576', (belonging to thread 4576)

Pro is a lot faster to load, delete etc. but contra is more difficult
to
count cross-tables and everything.

What could i do best?


As you said in the beginning :)

TABLE Category
ID
...
ParentID ... REFERENCES Table(ID)

TABLE Thread
ID
...

TABLE Message
ID
...
ThreadID ... REFERENCES Thread(ID)
ReplyTo ... REFERENCES Message(ID)

is one possibility coming from

1) Category may have subcategories (0..*)
2) Subcategory must have parent category (1)
3) Category consists of threads (0..*)
4) Thread consists of messages (1..*)
5) Message could either be top-level or a reply to one of the messages
in thread

Another possibility is a "linear" thread, i.e. posts are simply listed
one after another, in which case there is no ReplyTo field.
I wouldn't say that having a table for each thread is a good design.

Read some on relational database design :)
Btw, I think this is rather a topic for design or sql group :) Has
nothing to do with PHP :)
--

- lüpher
---------------------------------------------
"Man sieht nur das, was man weiß" (Goethe)
Jan 3 '06 #2
I agree, this is probably a good topic for a database forum, more than
for the PHP forum... but, since it is here:

What would be the advantage of having a table for each thread, does that
not go against the idea of database normalization? I would think that it
would cause quite a few duplicate fields, at least in the fact that each
'thread' table would be essentially the same.

Also, it seems to me that SQL / MySQL is very fast. If the database is
on a decent server what would be the speed advantage of each thread
having its own table?

Just curious, not bashing your idea Frizzle :)

Scot

Lüpher Cypher wrote:
frizzle wrote:
Hi there,

I'm going to build a simple forum in mySQL.
I've thought about it for a while now, but still can't figure it
out completely:

If i have say 5 main categories,
One has 5 sub-categories.
Each sub category consists of individual threads.
Wich each has the possibility to be commented.

The question concerns the thread & comments part.
My first idea was to create one table Threads, and one
Comments.
The Threads-table would have the original post, starting a thread,
and the Comments table would have the comment, and the id of
the thread it belongs to. (so all comments there are in the whole
forum)

Now i thought of the following:
I could create a new table for each thread to save it's comments in.
And call it e.g. 'Comments_4576', (belonging to thread 4576)

Pro is a lot faster to load, delete etc. but contra is more difficult
to
count cross-tables and everything.

What could i do best?


As you said in the beginning :)

TABLE Category
ID
...
ParentID ... REFERENCES Table(ID)

TABLE Thread
ID
...

TABLE Message
ID
...
ThreadID ... REFERENCES Thread(ID)
ReplyTo ... REFERENCES Message(ID)

is one possibility coming from

1) Category may have subcategories (0..*)
2) Subcategory must have parent category (1)
3) Category consists of threads (0..*)
4) Thread consists of messages (1..*)
5) Message could either be top-level or a reply to one of the messages
in thread

Another possibility is a "linear" thread, i.e. posts are simply listed
one after another, in which case there is no ReplyTo field.
I wouldn't say that having a table for each thread is a good design.

Read some on relational database design :)
Btw, I think this is rather a topic for design or sql group :) Has
nothing to do with PHP :)


--
Scot McConnaughay
Jan 3 '06 #3
Scot McConnaughay wrote:
I agree, this is probably a good topic for a database forum, more than
for the PHP forum... but, since it is here:

What would be the advantage of having a table for each thread, does that
not go against the idea of database normalization? I would think that it
would cause quite a few duplicate fields, at least in the fact that each
'thread' table would be essentially the same.

Also, it seems to me that SQL / MySQL is very fast. If the database is
on a decent server what would be the speed advantage of each thread
having its own table?

Just curious, not bashing your idea Frizzle :)

Scot

Lüpher Cypher wrote:
frizzle wrote:
Hi there,

I'm going to build a simple forum in mySQL.
I've thought about it for a while now, but still can't figure it
out completely:

If i have say 5 main categories,
One has 5 sub-categories.
Each sub category consists of individual threads.
Wich each has the possibility to be commented.

The question concerns the thread & comments part.
My first idea was to create one table Threads, and one
Comments.
The Threads-table would have the original post, starting a thread,
and the Comments table would have the comment, and the id of
the thread it belongs to. (so all comments there are in the whole
forum)

Now i thought of the following:
I could create a new table for each thread to save it's comments in.
And call it e.g. 'Comments_4576', (belonging to thread 4576)

Pro is a lot faster to load, delete etc. but contra is more difficult
to
count cross-tables and everything.

What could i do best?


As you said in the beginning :)

TABLE Category
ID
...
ParentID ... REFERENCES Table(ID)

TABLE Thread
ID
...

TABLE Message
ID
...
ThreadID ... REFERENCES Thread(ID)
ReplyTo ... REFERENCES Message(ID)

is one possibility coming from

1) Category may have subcategories (0..*)
2) Subcategory must have parent category (1)
3) Category consists of threads (0..*)
4) Thread consists of messages (1..*)
5) Message could either be top-level or a reply to one of the messages
in thread

Another possibility is a "linear" thread, i.e. posts are simply listed
one after another, in which case there is no ReplyTo field.
I wouldn't say that having a table for each thread is a good design.

Read some on relational database design :)
Btw, I think this is rather a topic for design or sql group :) Has
nothing to do with PHP :)


--
Scot McConnaughay


Well, thanks for the replies, and continuing the discussion here ...
It would certainly be a big bunch of duplicate fields, with exact the
same structure.

I know it would go against normalization, but on the other hand, i
thought it'd get a big deal faster if it knew in what table to search
immediately,
without skipping 1000-nds of comments not concerning the current
thread.
Maybe i'm just underestimating the power of PlayStat ... erm, mySQL.

I don't know beforehand how popular this forum will be, and how many
threads, and comments will be in it. I'm just affraid that it'll get
slow.
On the other hand, it'll be easier to count different things, combine
queries etc. when everything's in 1 table....

Frizzle.

Jan 3 '06 #4
Scot McConnaughay wrote:
I agree, this is probably a good topic for a database forum, more than
for the PHP forum... but, since it is here:

What would be the advantage of having a table for each thread, does that
not go against the idea of database normalization? I would think that it
would cause quite a few duplicate fields, at least in the fact that each
'thread' table would be essentially the same.
It does go against it :)
And that's just it - think of it this way:
Database is used to store information about the world (that has some
known objects)
Table is used to store information about different objects and/or how
they relate to each other
Fields are used to describe objects

When designing a database, it is best to first think of which objects
the world consists of. In this case, the world is the forum, the objects
are threads and messages. Then, one thinks about what attributes
describe objects (for example, a thread has a unique id, topic, etc., a
message has a unique id, date, maybe a name of the poster, etc.) Then
objects become tables and attributes become fields. Finally, relations
between them are made.

Putting each thread in a separate table is basically saying that each
thread is a different object..


Also, it seems to me that SQL / MySQL is very fast. If the database is
on a decent server what would be the speed advantage of each thread
having its own table?

Yes, it is :) You'll probably not see sufficient change in speed, unless
there is millions of records. So, I don't see any advantage in using
separate tables. I see a disadvantage, though :) First, one has to
remember that each table is stored in a separate file, plus, there are
index files. Then, suppose I want to add another attribute to thread.
Having one table, it's easy. Having thousands of tables - not so easy :)
--

- lüpher
---------------------------------------------
"Man sieht nur das, was man weiß" (Goethe)
Jan 3 '06 #5
frizzle wrote:
As you said in the beginning :)

TABLE Category
ID
...
ParentID ... REFERENCES Table(ID)

TABLE Thread
ID
...

TABLE Message
ID
...
ThreadID ... REFERENCES Thread(ID)
ReplyTo ... REFERENCES Message(ID)

is one possibility coming from

1) Category may have subcategories (0..*)
2) Subcategory must have parent category (1)
3) Category consists of threads (0..*)
4) Thread consists of messages (1..*)
5) Message could either be top-level or a reply to one of the messages
in thread

Another possibility is a "linear" thread, i.e. posts are simply listed
one after another, in which case there is no ReplyTo field.
I wouldn't say that having a table for each thread is a good design.

Read some on relational database design :)
Btw, I think this is rather a topic for design or sql group :) Has
nothing to do with PHP :)

--
Scot McConnaughay


Well, thanks for the replies, and continuing the discussion here ...
It would certainly be a big bunch of duplicate fields, with exact the
same structure.

I know it would go against normalization, but on the other hand, i
thought it'd get a big deal faster if it knew in what table to search
immediately,


I doubt it greatly :)
without skipping 1000-nds of comments not concerning the current
thread.
Maybe i'm just underestimating the power of PlayStat ... erm, mySQL.
Don't forget about indexes :) The primary key is always indexed so,
there is no "skipping" records. Event a binary tree index would get
there fast :) Say, if you have 16 million threads with 16 millions
consequent ids, and you want to retrieve 15.999.999-th record, you won't
have to skip 16 million records to get there :) With binary tree, it'll
only take 32 steps :)

I don't know beforehand how popular this forum will be, and how many
threads, and comments will be in it. I'm just affraid that it'll get
slow.


It is more likely that it'll be slow if the server won't be able to
handle the load :)

--

- lüpher
---------------------------------------------
"Man sieht nur das, was man weiß" (Goethe)
Jan 3 '06 #6
Lüpher Cypher wrote:
frizzle wrote:
As you said in the beginning :)

TABLE Category
ID
...
ParentID ... REFERENCES Table(ID)

TABLE Thread
ID
...

TABLE Message
ID
...
ThreadID ... REFERENCES Thread(ID)
ReplyTo ... REFERENCES Message(ID)

is one possibility coming from

1) Category may have subcategories (0..*)
2) Subcategory must have parent category (1)
3) Category consists of threads (0..*)
4) Thread consists of messages (1..*)
5) Message could either be top-level or a reply to one of the messages
in thread

Another possibility is a "linear" thread, i.e. posts are simply listed
one after another, in which case there is no ReplyTo field.
I wouldn't say that having a table for each thread is a good design.

Read some on relational database design :)
Btw, I think this is rather a topic for design or sql group :) Has
nothing to do with PHP :)
--
Scot McConnaughay


Well, thanks for the replies, and continuing the discussion here ...
It would certainly be a big bunch of duplicate fields, with exact the
same structure.

I know it would go against normalization, but on the other hand, i
thought it'd get a big deal faster if it knew in what table to search
immediately,


I doubt it greatly :)
without skipping 1000-nds of comments not concerning the current
thread.
Maybe i'm just underestimating the power of PlayStat ... erm, mySQL.


Don't forget about indexes :) The primary key is always indexed so,
there is no "skipping" records. Event a binary tree index would get
there fast :) Say, if you have 16 million threads with 16 millions
consequent ids, and you want to retrieve 15.999.999-th record, you won't
have to skip 16 million records to get there :) With binary tree, it'll
only take 32 steps :)

I don't know beforehand how popular this forum will be, and how many
threads, and comments will be in it. I'm just affraid that it'll get
slow.


It is more likely that it'll be slow if the server won't be able to
handle the load :)

--

- lüpher
---------------------------------------------
"Man sieht nur das, was man weiß" (Goethe)


Thanks Lüpher,

One question though; what i mean with skipping,
is that there are comments of multiple threads in 1 table.
This way, mysql has to skip the comments that do not concern
the current thread.

Would it be wise to make the related ID's indexes? Like:
Table 'Comments'
Fields - id (unique, primary, auto incr)
- thread_id (index)
- title
- etc.

Or am i getting confused?

Frizzle.

(ow yeah, your remark on changing the tables structure convinced
me of doing it all in 1 table)

Jan 3 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Frank Millman | last post by:
Hi all I would like some advice, and I hope that the good people on c.l.p will give me the benefit of their experience. I am busy developing an accounting package, using Python and wxPython,...
8
by: Keith Smith | last post by:
I know this is a little off topic but I hope it is still acceptable to this forum. Please read this carefully. I am not looking for a quick answer - I am hoping to find someone who has been in my...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
5
by: John Goodfellow | last post by:
I'm trying to find a .NET-centric alternative to the Plone CMS package. For those not familiar, Plone is an open source CMS built on the Zope application server which is built on Python. I'm the...
1
by: Ellen12c | last post by:
On the last post I asked about a code to make a vertical scroll bar and ends up I didn't need one. I was told by a big group of people on this forum that I needed to do away with all the flash and...
8
by: STG | last post by:
Greetings, My group has an SDK that was developed 5 years ago with VC++ 6. Over the last years, the requests for a VS.NET SDK has reached critical mass and I am now in the process of doing that....
3
by: lsmith | last post by:
Dear group, I am the new volunteer coordinator for a non-profit organization in Tucson, AZ. One of my main focuses is to develop our own volunteer pool using either MS Access 2002 or Excel...
2
by: =?Utf-8?B?QmlnU2Ft?= | last post by:
I hope I'm in the correct forum. Please advise if I need to move this question. I've a lead developer who insists on developing with classic ASP & VB6. He & his team have created an impressive...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.