Report with count of the posts made by each user

Last modified: February 22, 2008 - 02:05

Copy the following in the body of a page and set the input filter to PHP.

<?php
$how_many_per_page
= 100;

$query = "SELECT {node}.created AS Date, name, type, COUNT(*) AS Total
FROM {node} JOIN {users}
ON {node}.uid = {users}.uid
GROUP BY FROM_DAYS(TO_DAYS(FROM_UNIXTIME({node}.created))), name, type"
;

$count = "SELECT COUNT(*) FROM (SELECT DISTINCT FROM_DAYS(TO_DAYS(FROM_UNIXTIME({node}.created))) AS DATE,  uid, type FROM {node}) AS Data_row";

$results = pager_query($query, $how_many_per_page, 0, $count);

$header = array(t('Date'), t('Name'), t('Type'), t('Total'));

$attributes = array('width' => '75%',
                              
'align' => 'center',
                              
'border' => '2',
                            );

$rows = array();

while (
$quote = db_fetch_array($results)) {
     
$rows[] = array(date('Y/m/d',$quote['Date']),  $quote['name'], $quote['type'], $quote['Total']);
      }

if (
count($rows)) {
      echo
theme('table', $header, $rows, $attributes);
      echo
theme('pager', NULL, $how_many_per_page);
      }
      else { echo
'No results found'; }
?>

 
 

Drupal is a registered trademark of Dries Buytaert.