commentList($aid) );" peut être appelé."/> commentList($aid) );" peut être appelé.">

Maison  >  Article  >  développement back-end  >  Comment obtenir plusieurs réponses en php

Comment obtenir plusieurs réponses en php

藏色散人
藏色散人original
2021-12-09 10:59:081962parcourir

Comment implémenter plusieurs réponses en PHP : 1. Créez "function commentList($aid,$pid = 0,&$result=array()){...}" ; 2. Passez "$this->commentList ($aid);" peut être appelé.

Comment obtenir plusieurs réponses en php

L'environnement d'exploitation de cet article : système Windows 7, PHP version 7.4, ordinateur Dell G3.

Comment obtenir plusieurs réponses en php ?

Implémentation de la fonction de réponse aux commentaires illimitée 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;
}

Méthode d'appel

$this->commentList($aid);

Utilisez tp5 pour écrire la fonction de réponse aux commentaires d'article dans le projet

Utilisez le pid dans le tableau pour identifier l'identifiant de la table de réponse. La structure de la table est la suivante. suit

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

Apprentissage recommandé : " Tutoriel vidéo PHP

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn