php怎么实现多次回复

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;}

调用方法

$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怎么实现多次回复
标题路径:https://www.cdcxhl.com/article8/cgsdip.html

成都网站建设公司_创新互联,为您提供用户体验响应式网站自适应网站小程序开发品牌网站建设网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站制作