Anybody has idea about implementation of forum by php?
What I am going to do is to write a forum using php, which is multiple replies forum, i.e., any user can reply any thread. Threads can be seen either by either hierarchy or sequential order.
 
Solution1: MySQL data model
Messages:
    id int,
    newthread int,  // 1 means this is a new thread; 0 means this is a reply
    title varchar,
    author varchar,
    ... ...
 
Replies:
    parent int,  // the id of thread replied by reply
    reply int  // the id of reply thread
 
So, the listing threads function would do:
select * from Messages when newthread=1;
Save result set in $row,
For each $row,
select reply from Replies where parent = $row->id;
 
The above solution seems spend lots of time on finding all replies for each new thread by search the whole Replies table, i.e, how many new thread, how many times searching table Replies.
 
Solution 2. XML data store
<thread>
    <title>title1</title>
    <author>mike</author>
    <replies>
        <thread>
            <title></title>
            ... ...
        </thead>
        <thread>
            ... ...
        </thread>
    </replies>
</thread>
<thread>
     ... ...
</thread>
 
Put 100 thread in an XML file or threads of one day in an XML file. When listing all threads, just simply go through XML file, the correct order of threads displayed is just the order in XML file.
But it will cost some time on inserting thread. The only available method to write XML file is using DOM, which write all things in an XML to memory. After changing something, memory will be written to XML file. For a frequently accessed web site, this method seems not efficient enough.
 
Anybody has other ideas? Please share with me.
 
Shilun
 
 
 
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to