Re: Re: creating a threaded message system--sorting messages
| From: | Dan McCullough | Date: | Thu, 29 Jun 2006 22:23:23 +0000 |
| Subject: | Re: Re: creating a threaded message system--sorting messages | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-238943@lists.php.net to get a copy of this message | ||
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 2Post4 - 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@kermodebear.org> 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-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpWouldn't that involve a separate SQL query for every post?