php实现多次回复的方法:1、创建“function commentList($aid,$pid = 0,&$result=array()){…}”;2、通过“$this->commentList($aid);”方式调用即可。
本文操作环境:Windows7系统,PHP7.4版,Dell G3电脑。
php怎么实现多次回复?
PHP无限级评论回复功能实现
protected function commentList($aid,$pid = 0,&$result=array()){ $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;}
登录后复制
调用方法
立即学习“PHP免费学习笔记(深入)”;
$this->commentList($aid);
登录后复制
项目中使用tp5写文章评论回复功能
表中使用pid来标识回复表的id 表结构如下
CREATE TABLE `bcpub_article_comment` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`author_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '作者ID',`article_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '文章ID',`pid` int(11) unsigned NOT NULL DEFAULT '0',`uid` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '评论人ID',`comment` varchar(250) NOT NULL DEFAULT '',`give_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '评论点赞数量',`add_time` int(10) unsigned NOT NULL DEFAULT '0',PRIMARY KEY (`id`),KEY `author_id` (`author_id`),KEY `pid` (`pid`)) ENGINE=MyISAM AUTO_INCREMENT=97 DEFAULT CHARSET=utf8 COMMENT='文章评论表'
登录后复制
推荐学习:《PHP视频教程》
以上就是php怎么实现多次回复的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2095544.html