Completely lost in creating nested comments

Hi,
I’m trying to figure out how to store and return nested comments (like reddit)

This is my viewthread php file of my forum where it you can add a comment. I want to be able to create nested comments so you can respond to another comment. Currently you can only add a comment under the thread which appears in date order but you can’t respond to another comment
Here’s my table titled Posts (for comments)
describe Posts;

+---------------+-----------------+------+-----+---------------------+-------------------------------+
| Field         | Type            | Null | Key | Default             | Extra                         |
+---------------+-----------------+------+-----+---------------------+-------------------------------+
| id            | int(6) unsigned | NO   | PRI | NULL                | auto_increment                |
| User          | varchar(30)     | NO   |     | NULL                |                               |
| PostTimeStamp | timestamp       | NO   |     | current_timestamp() | on update current_timestamp() |
| CommentText   | varchar(8000)   | YES  |     | NULL                |                               |
| IDOfThread    | int(11)         | YES  |     | NULL                |                               |
| Upvotes       | int(11)         | NO   |     | 0                   |                               |
| ParentId      | int(11)         | YES  |     | NULL                |                               |
+---------------+-----------------+------+-----+---------------------+-------------------------------+
7 rows in set (0.002 sec)

And here’s viewthread php

Well, not really sure what you are asking help with. But, normally, if you are wanting to “nest” a thread and display it with all the posts, you would just process a query set up correctly to do so.

Loosely, you would do something like SELECT * FROM posts WHERE IDofThread=thread-wanted.
That would give you all the posts for that one thread. You probably would want to ORDER BY PostTimeStamp so that they are in order. (DESC or ASC depending on last first or first first)
And, even, you might want to set up limits to show only 10 posts and set up pagination for seeing more.
You would have to loop thru all the posts for that one thread and then display the text for each.

Is that what you are asking help with?

Sponsor our Newsletter | Privacy Policy | Terms of Service