Yesterday we talked about counting the number of nodes by user.
Drupal 7 – Get the number of nodes by user
We could also use similar approach for counting the number of comments by user.
1. Add the following function in your theme template.php
function <theme>_get_user_comments_count($uid) {
$query = db_select('comment', 'c');
$query->condition('uid', $uid, '=');
$query->condition('status', '1', '=');
$query->addExpression('COUNT(1)', 'count');
$result = $query->execute();
if ($record = $result->fetchAssoc())
return $record['count'];
return 0;
}
Continue reading Drupal 7 – Get the number of comments by user

