2

I'm new to Drupal, and I want to make an overview over aggregated user data related to the articles they have written.

I basically want to build a table like this:

------------------------------------------------------
| user | articles published | articles with comments |
------------------------------------------------------
| bob  |                 12 |                      3 |
------------------------------------------------------
| sue  |                 34 |                      0 |
------------------------------------------------------
| kim  |                  0 |                      0 |
------------------------------------------------------

What is the best way to make a table like this? Is this something I need to make my own module for?

Would it be possible to aggregate this with an existing module?

  • Which version of Drupal you are using ? – Anil Sagar Sep 22 '12 at 8:28
  • I'm using Drupal 7.15. – Bohr Sep 22 '12 at 8:31
  • Ok, You can use below code then in a custom block with format as PHP. I hope you are using default Article Content Type that comes with Drupal Installation. – Anil Sagar Sep 22 '12 at 8:36
1

Welcome to the Drupal StackExchange !

You can achieve this with some custom php code and couple of queries.

<?php

   $articles_publishers = db_query("SELECT DISTINCT u.uid FROM {node} n LEFT JOIN {users} u on n.uid = u.uid where n.type = 'article'");
   foreach ($articles_publishers as $articles_publisher) {
     $publisher = user_load($articles_publisher->uid);
     $username = theme('username', array('account' => $publisher));
     $articles_published = db_query("SELECT count(*) FROM {node} where uid = :uid and status = 1 and type='article'", array(':uid' => $articles_publisher->uid))->fetchField();
     $articles_published_with_comments = db_query("SELECT count(*) FROM {node} n INNER JOIN {comment} c ON n.nid = c.nid where n.uid = :uid and n.status = 1 and n.type='article'", array(':uid' => $articles_publisher->uid))->fetchField();

     // Theme the information with above results

     print "Username :" . $username;
     print "articles published :" . $articles_published;
     print "articles with comments :" .  $articles_published_with_comments;
   }

?>

use above code in a module custom block or Add Block with php option to display the information.

Hope it helps.

  • Thank you! When I go through the Add block form, I never see any "php option". Is this due to my Drupal verson (7.15), or am I just missing it? – Bohr Sep 22 '12 at 8:39
  • Enable PHP filter module to see the PHP format ! – Anil Sagar Sep 22 '12 at 8:47
  • Aha! Tanks Anil! Sorry about not voting you up, I don't have enough reputation yet :-) – Bohr Sep 22 '12 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.