You are here: Re: page commenting « All PHP « IT news, forums, messages
Re: page commenting

Posted by danarz on 09/14/06 03:04

Thanx!

What's the "nested set model"?
What's the "adjacency model"?"

My board is usually considered slow. But occasionally, I can get very
large amount of traffic... so I am not sure if I should use this. But,
simply learning the logic is interesting.

Again thanks for the help and idea.


it could probably benefit from the nested set
> model to check hierarchy instead of the adjacency model.
Rik wrote:
> danarz@gmail.com wrote:
> > No, but it's similar.
> > I already have pages that are identifies by an id in the url (just
> > like a BB)
> >
> > Now, I added a commenting script at the bottom of the page.
> > But, I want users to be able to respond to the comments, and than to
> > be able to leave comments to specific responses.. and than continue to
> > create comments to the new responses, therfore creating treads to each
> > comment or threads to each responses.
> >
> > In PHPBB and most BB's the commenting system is linear. That is, you
> > can only post comment to the original article and use quots of other
> > posts.
> >
> > I am having problem with comming up with the php logic and the mysql
> > database design.
> >
> >
> > Here is a visual representation:
> >
> >
> > ---
> > Article/web page
> > ---
> > comment 1
> > response1 to comment1
> > Comment 2
> > response #a to comment2
> > response #b to response #a
> > response #c to response #a
> > response#d to response#c
> > response #x to response #d
> > response#e to comment2
>
> Well, the database design could be really simple.
>
> TABLE comments
> id int(8) PRIMARY KEY
> text text
> timestamp
> parent int(8) INDEX
>
> And in parent the ID of the comment it is a reply to. For the 'root'
> comment you've got several options: create a dummy 'root' comment where all
> new comments are direct childs, or something I've also seen is to refer to
> itself as it's parent.
>
> With simple logic you could export nested ul's:
>
> function show_comments($id=false){
> if($id===false){
> $query = 'SELECT * FROM comments WHERE id = parent';
> } else {
> $query = 'SELECT * FROM comments WHERE id != parent AND
> parent='$id;
> }
> $result = mysql_query($query);
> if(mysql_num_rows() < 1 || mysql_error()){
> return '';
> }
> $return = '<ul>';
> while($row=mysql_fetch_assoc($result)){
> $return .= '<li>'.$row['comment'].show_comments($row['id'])'</li>';
> }
> $return .= '</ul>';
> return $return;
> }
>
> This is a terribly simplified solution, adequate for small boards/sites.
> Draback is the amount of queries it takes to build just one thread. If your
> site becomes very, very big, it could probably benefit from the nested set
> model to check hierarchy instead of the adjacency model.
>
> Grtz,
> --
> Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация