|
Posted by Rik on 09/11/06 20:49
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]
|