php解答:php怎么实现多次回复

 所属分类:php教程

 浏览:49次-  评论: 0次-  更新时间:2022-09-21
描述:更多教程资料进入php教程获得。 php实现多次回复的方法:1、创建“function commentList($aid,$pid = 0,&$result=array()){...}”;2、...
更多教程资料进入php教程获得。

php实现多次回复的方法:1、创建“function commentList($aid,$pid = 0,&$result=array()){...}”;2、通过“$this->commentList($aid);”方式调用即可。

php零基础到就业直播视频课:进入学习
程序员必备接口测试调试工具:立即使用

本文操作环境: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怎么实现多次回复的详细内容,更多请关注zzsucai.com其它相关文章!

 标签: php,
积分说明:注册即送10金币,每日签到可获得更多金币,成为VIP会员可免金币下载! 充值积分充值会员更多说明»

讨论这个素材(0)回答他人问题或分享使用心得奖励金币

〒_〒 居然一个评论都没有……

表情  文明上网,理性发言!