zoukankan      html  css  js  c++  java
  • 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='文章评论表'

  • 相关阅读:
    POJ 1873 The Fortified Forest
    C语言中time函数获取系统时间
    回车符号与换行符号
    [转]NYOJ-511-移动小球
    C语言的inline
    C语言编译全过程
    linux下面安装配置mongoDB
    linux下面安装配置LAMP环境
    linux下面的解压缩文件的命令
    day23 正则,re模块
  • 原文地址:https://www.cnblogs.com/ccs-mxs/p/13973912.html
Copyright © 2011-2022 走看看