D
D
Drembler2018-04-19 04:15:49
MySQL
Drembler, 2018-04-19 04:15:49

How to implement replies to comments?

The site has a comment system.
It is necessary to implement the ability to reply to a comment similar to that used on a toaster, for example:
@my_user_name, comment text...
Only here there is no unique username on the site, but there are ordinary names and id.
Ivan, the text of the comment...
How can this be implemented in the interface and how to arrange it in the database?
I suppose you need to add a hidden field for the id of the user who is being answered, and when you click the answer button under the comment, fill in this field, and add a name at the beginning of the comment. In the database, add a for column to store this id.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2018-04-19
@Drembler

Add to comments parent_id
null - first level comment.
Or enter the ID of the parent comment if this is a response to some comment.
The classic tree structure is the same.
The user does not need to be pulled at all, well, except for the standard author_id or whatever it is with you.

K
Kolya, 2014-04-04
@Anemo

I wrote in general.
A slightly different example, but the meaning is the same)
jsfiddle.net/cnr28/1
or like this: jsfiddle.net/cnr28/2
here 1 class for blocks, fewer selectors

B
Blah Blag, 2014-04-04
@dsadasdad

Nowhere to be seen even a position relative. Float left should be, you can’t get off with one inline. Upload to jsfiddle.net and we'll see

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question