Community Documentation

Users by Percent Site Content

Last updated October 4, 2008. Created by IceCreamYou on October 4, 2008.
Log in to edit this page.

This snippet will display a table of users ordered by the percent of the site's content (nodes and comments) that they authored.

<?php
$limit
= 10; //The number of users to display.
$round = 1; //The number of digits after the decimal point to round to.  On larger sites, use larger values.
$uids = db_query_range("SELECT ROUND((cn + cc) / (SELECT (COUNT(n.nid) + COUNT(c.cid)) percent FROM node n LEFT JOIN comments c ON n.nid = c.nid) * 100, %d) percent, n.uid FROM (SELECT COUNT(nid) cn, uid FROM node GROUP BY uid) n LEFT JOIN (SELECT COUNT(cid) cc, uid FROM comments GROUP BY uid) c ON n.uid = c.uid GROUP BY uid ORDER BY percent DESC", $round, 0, $limit);
while (
$u = db_fetch_array($uids)) {
 
$uid = $u['uid'];
 
$pc = $u['percent'];
 
$user = user_load(array('uid' => $uid));
  if (
$pc > 0) {
   
$rows[] = array(theme_username($user), 'percent' => $pc);
  }
}

$header = array('User', 'Percent of Site Content');
print
theme_table($header, $rows);
?>

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 5.x, Drupal 6.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here