verdrm Posted February 19, 2008 Share Posted February 19, 2008 How do I make threaded comments? Currently I can echo all of the comments from an array, but how do I echo them in such a way that it shows: Comment 1 Comment 2 Comment 3 Comment 4 Thanks in advance! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 19, 2008 Share Posted February 19, 2008 How do you store your data? That will make a big difference on how you produce it Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 19, 2008 Author Share Posted February 19, 2008 MySQL while(list($comment) = mysql_fetch_array($result, MYSQL_NUM)) { echo $comment; } Something like that. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 19, 2008 Share Posted February 19, 2008 still doesn't show me how you Store the data that is how you display the data Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 19, 2008 Author Share Posted February 19, 2008 OK, I store the data in rows containing the columns: 'date', 'name', 'comment'. Does that help? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 19, 2008 Share Posted February 19, 2008 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. Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 19, 2008 Author Share Posted February 19, 2008 Is there a way using <UL> or some cheap method to just get the threaded look? Basically I just want: Comment 1 Comment 2 Comment 3 ....that look. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 19, 2008 Share Posted February 19, 2008 Show me more than 3 threads worth of post do you just want Comment 1 Comment 2 Comment 3 Comment 4 Comment 5 Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 19, 2008 Author Share Posted February 19, 2008 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"? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 19, 2008 Share Posted February 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 20, 2008 Author Share Posted February 20, 2008 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; } ?> Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 22, 2008 Author Share Posted February 22, 2008 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; } ?> Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 22, 2008 Share Posted February 22, 2008 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? Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 23, 2008 Author Share Posted February 23, 2008 Actually, on the particular page this comment system will be on, every comment is a reply to another, because it is only between two people. How do I use the above code that member provided to indent? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 23, 2008 Share Posted February 23, 2008 Its hard to implement something if you don't even have a clear idea of what you want. Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 23, 2008 Author Share Posted February 23, 2008 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; } ?> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 23, 2008 Share Posted February 23, 2008 maybe u should read cause I posted that and then said that you have no clue what you want. Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 24, 2008 Author Share Posted February 24, 2008 I didn't say that I had no clue what I wanted, I said I didn't know (at the time) how to use the code that you provided and I asked if you could implement what you provided into the code I provided. I've figured out a solution now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.