List of popular users

gercheq - August 5, 2009 - 02:59

I want to sort the users by popularity (users with the most bookmarks(another drupal module) will be listed at the top). I am using the bookmarks module and created the user list view as explained in http://views-help.doc.logrus.com/help/views/example-users-by-role

I just started learning drupal so any help will be appreciated.

Thanks,

solution

gercheq - August 5, 2009 - 04:11

this helped http://drupal.org/node/509532

<?php
$users
= db_query("SELECT COUNT(n.nid) count, u.name, u.uid, u.picture FROM {users} u LEFT JOIN {node} n ON u.uid = n.uid WHERE u.uid != 0 AND u.uid != 1 AND n.uid = u.uid AND u.status = 1 AND n.status = 1 GROUP BY n.uid ORDER BY count DESC LIMIT 10");


$output = "<ul>";
while (
$user = db_fetch_object($users)) {

   
//check user has a picture & it exists if not show default image
   
if ($user->picture && file_exists($user->picture)) {
     
$picture = $user->picture;
    }
    else  {
     
$picture = "default.png"
    } 
 
$output .= "<li><div class='user-thumb'><img src='/" . $picture ."' /></div><div class='user-name'>" . l($user->name, drupal_get_path_alias("user/{$user->uid}")). " ($user->count)</div></li>";


}
$ouput .= "</ul>";
echo
$output;
?>

 
 

Drupal is a registered trademark of Dries Buytaert.