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='文章评论表'

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值