Tell me how to properly organize tree comments. Algorithm, what properties, methods, technologies. Generally I can not figure out how to make an answer to an existing comment. Please help send in the right direction in this matter.

Closed due to the fact that the issue is too general for the participants Alexey Shimansky , user194374, Alex , pavel , Denis Bubnov 14 Dec '16 at 11:04 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See β€œHow to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Specify your question - what exactly causes difficulties, what you have already tried, why it did not fit. In the current wording of your question can not give a definite answer. - Alexey Ukolov
  • one
    You need Nested sets - u_mulder

1 answer 1

If it is very crude to depict this, then you can add to the class the property responsible for storing the ID of the comment that is answered with the current one. This is probably the most obvious solution.

 class Comment { private $id; //Π˜Π΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ коммСнтария private $from_id; //Π˜Π΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ коммСнтария, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΎΡ‚Π²Π΅Ρ‡Π°ΡŽΡ‚ private $text; //ВСкст коммСнтария private $date; //Π”Π°Ρ‚Π° ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠΈ коммСнтария private $like; //ΠšΠΎΠ»ΠΈΡ‡Π΅ΡΡ‚Π²ΠΎ Π»Π°ΠΉΠΊΠΎΠ² Ρƒ коммСнтария public function __construct($id = 0, $text="SIMPLE TEXT", $date="21.12.2012 12:00:00", $from_id = NULL) //ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€ { $this->id = $id; $this->from_id = $from_id; $this->text = $text; $this->date = $date; $this->like = 0; } public function __destruct() { } public function updateText($text="SIMPLE TEXT"){//Π Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ тСкста $this->text = $text; } public function addLike(){ //Π›Π°ΠΉΠΊ $this->like++; } } 

Well, here is a simple and rude (!!!) processing of the form:

 $com1 = new comment(1, $_POST['commentText'], date("dmY H:i:s")); //ΠžΠ±Ρ‹Ρ‡Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ $com2 = new comment(2, $_POST['commentText'], date("dmY H:i:s"), 1);//ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ-ΠΎΡ‚Π²Π΅Ρ‚ Π½Π° ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠΉ 

You can also add a username, ID generation, etc. to the class, but I think you will figure it out for yourself.

  • one
    rather, the top-level comment $ from_id will be equal to 0, and for the nested value , Jonny Manowar