0

I'm new to Drupal, and I'm using Organic Groups to make groups. The site is supposed to be a multi-blog platform where groups can have their own group and the group admin(only) should be able to get a list of all group members (linked to their blogs) in the side menu. How am I able to achieve this? Any help would be appreciated!

I found the following code from here:

<?php
    $query = db_select('node', 'n');
    $query->join('users', 'u', 'n.uid = u.uid');
    $query->join('file_managed', 'f', 'f.fid = u.picture');
    $query->fields('u',array('name'));
    $query->fields('n',array('type'));
    $query->fields('f',array('filename'));
    $query->fields('u',array('uid'));
    $query->condition('u.status', 1);
    $query->condition('n.status', 1);
    $query->condition('n.type', 'blog', '=');
    $query->addExpression('COUNT(n.uid)');
    $query->groupBy('u.uid');
    $query->groupBy('n.type');
    $query->orderBy('COUNT(n.uid)', 'DESC');
    $result = $query->execute();
    $output = array();
    while($record = $result->fetchAssoc()) {
    // print $record ;
     $output = '<div class="bloglist_row">';
     $output .= '<div class="bloglist_userimage"><img style="width:100%;" src="./sites/default/files/styles/thumbnail/public/pictures/'.$record['filename'].'"></div>';
     $output .= '<div class="bloglist_row_body"><a href="blog/'.$record['uid']. '">'.$record['name']. 's Blog</a><br />Posts: ('.$record['expression'].')</div>';
     $output .= '</div>';
     $output .= '<img src="blog_spacer.jpg" width="220" height="25" />';
   //  $output .= '<li />'.l($record['name']. ' ('.$record['expression'].')', 'blog/'.$record['uid']);
    }
    echo $output;
?>

Unfortunately this gives me the following error: Notice: Array to string conversion in include() on the last line (echo $output).

Any ideas on how I can achieve this with using Views?

1 Answer 1

0

Try setting $output = array(); to $output = ''; and see if that fixes the issue. Also, I would recommend using views instead of custom SQL query while dealing with Drupal.

1
  • No errors now, but it doesn't list the blogs. Probably a reason why I shouldn't use custom SQL queries, right? Still I'm not sure how to achieve this goal with Views.
    – janlindso
    Commented Sep 22, 2014 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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