Jump to content

Threaded Comments


verdrm

Recommended Posts

you can't threat it unless you have some sort of data you want to thread it off of.

 

Forums work by having the data be stored in rows that include

 

BoardID (for this post its PHP Help)

ThreadID (For this its Threaded Comments)

ReplyID (should be the 6th post so ID of 5)

 

Then you can do threading based on ThreadID when its a new ID new thread.

Link to comment
Share on other sites

You have the right idea. I just want to echo information to conform to the threaded look, although it does not have to follow any actual threaded type thing. I just want the threaded "style". The order would just be by date, which I already have in my SELECT statement.

 

Echoed comments should look like:

 

Comment 1

<indent>Comment 2

Comment 3

<indent>Comment 4

Comment 5

 

Is there a way to just get the threaded "look"?

Link to comment
Share on other sites

just to help you avoid confusion threading is defined as stuff grouped by something i.e a thread in a forum what you want is the alternation while loop scheme.

<?php
$i = 0;
while(TRUE){
if($i%2 === 0){
   echo "    ";
}
echo "Some text";
$i++;
}
?>

The $i modulus 2 will allow you to do alternating patterns in a loop

Link to comment
Share on other sites

Do you mind implementing that into the following code? I'm kind of confused as to how it works.

 

How would it work if the following code is used to display all of the comments?

 

<?php

$query = "SELECT comment FROM comments WHERE something = 'something' ORDER BY date";

$result = mysql_query($query);

 

while(list($comment) = mysql_fetch_array($result, MYSQL_NUM)){

 

echo $comment;

}

?>

Link to comment
Share on other sites

Do you mind implementing that into the following code? I'm kind of confused as to how it works.

 

How would it work if the following code is used to display all of the comments?

 

<?php

$query = "SELECT comment FROM comments WHERE something = 'something' ORDER BY date";

$result = mysql_query($query);

 

while(list($comment) = mysql_fetch_array($result, MYSQL_NUM)){

 

echo $comment;

}

?>

Link to comment
Share on other sites

I'm not one to tell people when they can and can't thread stuff, after all it's up to you to decide for yourself.  But I will say that generally you can only thread items when there is a parent-child relationship between them.  Or in other words, one of the items has to belong to the other.

 

So what you're telling me is that on your site, if I'm viewing a page with 10 comments, you want the comments to indent every other one, even when one of them is not a direct reply to another?

 

Might I suggest just alternating the background color of every other comment, rather than indentation?

Link to comment
Share on other sites

No offense, but if you read the thread, you will see that it is completely clear what I want. A member above provided this code:

 

<?php

$i = 0;

while(TRUE){

if($i%2 === 0){

  echo "    ";

}

echo "Some text";

$i++;

}

?>

 

 

I would like to know how to implement that into this, so that every other comment indents:

 

 

 

<?php

$query = "SELECT comment FROM comments WHERE something = 'something' ORDER BY date";

$result = mysql_query($query);

 

while(list($comment) = mysql_fetch_array($result, MYSQL_NUM)){

 

echo $comment;

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.