回声博客上的评论数量

时间:2014-05-06 15:04:51

标签: php count

我正在创建一个人们可以回复的博客。现在根据博客和上面的评论。我想显示已在该博客上发布的评论数量。有没有人有任何想法?

这是显示评论的php

<?php foreach($item->comments->find_all() as $comment) : ?>
                <?php echo View::factory('modules/comment', array(
                    'comment'   =>  $comment)); ?>
                <?php endforeach; ?>

感谢

1 个答案:

答案 0 :(得分:0)

您可以使用count()Funktion:

 count( $item->comments->find_all() );

或者用SQL直接计算数据库条目(在我看来,这是更好的解决方案)。但我不知道你的数据模型。 它会是这样的:

SELECT COUNT(*) FROM ... WHERE ...

查看http://de3.php.net/manual/de/function.count.php

相关问题