![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Aug 2005
Location: null
Posts: 40
Rep Power: 0
![]() |
Hi,
I was wondering how for example is the structure of this forum represented in a relational database ? (new threads, replies, etc) If you can offer some links, I will be thankful. greetings |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Probably something like:
CREATE TABLE threads ( id int(11) NOT NULL auto_increment, parent_id int(11) NULL, author_id int(11) NOT NULL, contents TEXT, PRIMARY KEY (id), KEY author_id ); However, if one wanted to display a tree structure of all the nodes at once (this forum just displays the titles of the threads), one would need one SQL query per node - not a very efficient way of doing things. I came up against this problem when designing a database-driven finance package for myself. In the end, I decided to live with the inefficiency as I had only a small number of nodes in my tree structure. There are more complicated and more efficient ways to store tree data in a relational database, but the above method I outlined is the simplest I know of. Edit: These forums may take a slightly different approach, since threads here are one-directional. They don't branch off into sub-threads. So the database structure might look more like: CREATE TABLE threads ( id int(11) NOT NULL auto_increment, author_id int(11) NOT NULL, contents TEXT, PRIMARY KEY (id), KEY author_id ); CREATE TABLE followups ( id int(11) NOT NULL auto_increment, parent_id int(11) NULL, author_id int(11) NOT NULL, contents TEXT, PRIMARY KEY (id), KEY author_id, KEY parent_id ); |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Aug 2005
Location: null
Posts: 40
Rep Power: 0
![]() |
Thank you Arevos. I couldn't find anything specific on that topic in the Internet. And that's what I needed most: sample code. Seems like the Internet can't replace a human's shared experience.
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|