Re: Re: creating a threaded message system--sorting messages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've come into this discussion pretty late so please bear with me if I
go over something that has been ruled out.

You are trying to print out in a threaded method the first post in a
thread followed by each post after that, that is a child/reply to that
post.  Is that correct?

So something like

Example 1

Thread1
 Post1
   Post2
     Post3
       Post4
         .....

or

Example 2

Thread1
 Post1
   Post2 - reply to post 1
    Post3 - reply to post 2
   Post4 - reply to post 1
   Post5 - reply to post 1
    Post6 - reply to post 2
     Post7 - reply to post 3


Example 1 is very common and is the easiest to implement.  From what I
remember you would need a couple of DB tables for post, post_thread,
post_post, thread

So for your question thread isnt very relative but I thought I would
throw it in.

thread {
threadid int(11) auto_increment,
threadname
threadsort
...

thread_post {
threadid int(11)
postid int(11)
....

post {
postid int(11) auto_increment,
postname
posttext
...

post_post
postid int(11),
postid2 int(11)
....

Please note I have two kids fighting over the cat, trying to cook
dinner and stave off a flood of water from the rising river so the SQL
structure is for example.

You can get everything in one query from the DB and lay it out based
on the id of the post, if you DB is properly indexed and setup and
queries are optimized you'll hardly notice a blip when the load gets
up.  You do not want to be doing multiple queries on a page when one
well written query will do the trick.

Either way if this is more what you are looking for we can get into
specifics later.

Dan


On 6/29/06, KermodeBear <php@xxxxxxxxxxxxxxx> wrote:
Hello,

As Adam pointed out, this can be deadly to your database, especially as the
number of posts grows. If you want to go that route, I would recommend
selecting all the posts in that particular thread and sorting the data out
in PHP somehow. No need to slam your database with (potentially) hundreds of
queries to display a discussion. Multiply that by several page views at
once...

If you don't mind the extra work and investigation, I would recommend
downloading some PHP forum software that supports threaded discussion and
see how they implement it. I found several listed in DMOZ:
http://dmoz.org/Computers/Programming/Languages/PHP/Scripts/Forums/

Let us know what you come up with! I'd like to see how you work this out.
This is a good computer science type of problem with practical application -
the kind of stuff they should have taught me in school but never did. ~(o:

Best of luck,

-K.Bear

> <SOLVED>, almost. I read the article suggested by K.Bear and found the
> recommended solution to be a bit more complicated than I wanted to
> implement. I then found another way to do this using the existing
> "Adjacency List Model" through a recursive function. So basically, you
> query the database for the post_id of the very first post in the
> discussion. You then call a function that displays that post, searches
> for all children of that post and then calls itself recursively on
> each of the children it discovers. This works great for spitting out
> the posts in the proper order. Now I'm trying to figure out how to
> make sure the indenting looks right in the browser.
>
> - Ben
>
>> Wouldn't that involve a separate SQL query for every post?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux