How to realize multiple replies by php
This article introduces the knowledge of "how to reply multiple times by php". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Php to achieve multiple reply method: 1, create "function commentList ($aid,$pid = 0 recently received resultreply array ()) {...}"; 2, through the "$this- > commentList ($aid);" method can be called.
This article operating environment: Windows7 system, PHP7.4 version, Dell G3 computer.
How does php reply multiple times?
Implementation of unlimited level comment reply function in PHP
Protected function commentList ($aid,$pid) {$arr = ArticleComment::relation (['usertalent'= > function ($query) {$query- > field (' id,talent_usernickname,talent_avatar');}])-> where (['pid' = > $pid])-> where ([' article_id' = > $aid])-> order ('id desc')-> select (); if (empty ($arr)) {return array () } foreach ($arr as $cm) {$thisArr=&$result []; $cm ["children"] = $this- > commentList ($aid,$cm ["id"], $thisArr); $thisArr= $cm;} return $result;}
Call method
$this- > commentList ($aid)
Use tp5 to write articles, comment and reply in the project.
The id table that uses pid to identify the reply table in the table has the following structure
CREATE TABLE `comment` (`id`int (11) unsigned NOT NULL AUTO_INCREMENT, `author_ id` int (11) unsigned NOT NULL DEFAULT'0' COMMENT 'author ID', `article_ id`int (11) unsigned NOT NULL DEFAULT' 0' COMMENT 'article ID', `pid`int (11) unsigned NOT NULL DEFAULT' 0comment, `uid`int (11) unsigned NOT NULL DEFAULT'0' COMMENT 'commentator ID', `comment`varchar (250) NOT NULL DEFAULT', `give_ count`int (10) unsigned NOT NULL DEFAULT'0' COMMENT 'number of likes `add_ time` int (10) unsigned NOT NULL DEFAULT '0immediate primary KEY (`id`), KEY `author_ id` (`pid`), KEY `pid` (`pid`) ENGINE=MyISAM AUTO_INCREMENT=97 DEFAULT CHARSET=utf8 COMMENT=' article comment table' "how to achieve multiple replies by php" ends here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!