我的网站中有一个部分,我确实需要计算特定帖子的评论数量。实际上,我已经构建了一个用于检索评论数据库表中所有数据的函数(函数 getComments)。
评论数据库表结构是:id(PK)| 作者 ID | 日期时间 | 邮编 | 文本
现在,因为我只需要计算它们(评论),我想知道是否更好地使用服务器资源/冗余:
$comments=new Comment();
$comments->getComments();
echo count($comments);
或者我最好构建另一个函数(除了'getComments'):
function countComments($postid)
{
//count comments per post
}
谢谢
卢卡