新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
php怎么實(shí)現(xiàn)多次回復(fù)
本文操作環(huán)境:Windows7系統(tǒng),php7.4版,Dell G3電腦。

php怎么實(shí)現(xiàn)多次回復(fù)?
PHP無限級(jí)評(píng)論回復(fù)功能實(shí)現(xiàn)
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;
}
調(diào)用方法
$this->commentList($aid);
項(xiàng)目中使用tp5寫文章評(píng)論回復(fù)功能
表中使用pid來標(biāo)識(shí)回復(fù)表的id 表結(jié)構(gòu)如下
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 '評(píng)論人ID', `comment` varchar(250) NOT NULL DEFAULT '', `give_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '評(píng)論點(diǎn)贊數(shù)量', `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='文章評(píng)論表'
新聞名稱:php怎么實(shí)現(xiàn)多次回復(fù)
新聞來源:http://www.dlmjj.cn/article/djcicdi.html


咨詢
建站咨詢
