Display (x) last logged in userpictures

Last modified: October 26, 2009 - 20:36

I made this for communities and it show userpictures of people who have logged in. I am no expert in php (but i know programming in other languages) and I made this from other php snippets. It may need more testing but it seems to work fine on this version of drupal (4.6.3). It looks nice and it enhances the community-feeling. It will only show those users who have uploaded a picture.

<?php

//show user pictures ---------------------------
//not tested. Will only show those users who have a picture
global $user;
$count2 = 8; //how many pictures to show, change this value
//
$count = $count2+10; //how many users in total with or without pictures
$co=0;

print
'<TABLE BORDER="1" CELLPADDING="5"  CELLSPACING="10" WIDTH="100%"><TR><TD>';

$result = db_query("SELECT * FROM {users} as u where status=1 ORDER BY changed DESC");
  while ((
$user_info = db_fetch_object($result)) & $co<$count) {
   if(
$user_info->uid){
       if(
$user_info->picture){
           if (
$co<$count2){
              print
'<a href="/user/'.$user_info->uid.'">
<img src="/'
.$user_info->picture.'"  hspace=5 ></a>';
$co++;
           }
        }
   }
}
print
'</TD></TR></TABLE>';
//------------------------------------------------------

?>

How I Did It...

Sverre - March 29, 2006 - 20:48

I needed a list of the last (x) logged in user pictures. This snippet shows a list of pictures rather than across the page as in the original above. It also checks if the user has a picture, and shows just their username if no picture is present.
Tested okay with Drupal 4.6.

<?php
//
//  Show list of (x) last logged on users
//  *************************************
//  See drupal.org/node/44587 - Posted by Sverre
//  If user has no picture will show username instead
//  Includes title attribute in link
//  Tested okay with Drupal 4.6
//  Change '$list_no' to increase / decrase list
//
$list_no = 5;
$sql = "SELECT u.uid, u.name, u.status, u.changed, u.picture FROM {users} u WHERE u.status = 1 ORDER BY u.changed DESC LIMIT $list_no";
$output = '<div class="item-list"><ul>';
$result = db_query($sql);
while (
$auser = db_fetch_object($result)) {
  if (
$auser->picture) {
   
$showthis = '<img src="'.$auser->picture.'" />'; // Show Picture
 
} else {
   
$showthis = $auser->name; // Show Text
 
}
 
$output .= "<li>".l($showthis, "user/$auser->uid", array ("title" => "View ".$auser->name."'s profile."), null, null, FALSE, TRUE)."</li>";
}
$output .= "</ul></div>";
print
$output;
?>

This is the first snippet I've posted, so get in quick with any 'critiquing' before I post any more! ;-)

I can't get this to work

toma - July 2, 2006 - 11:05

I can't get this to work with drupal 4.7.2 and how i can change the image view to "vertical"

Thank you

For 4.7.x

Sverre - August 15, 2006 - 22:31

toma and bxy (by email),
It would appear that in 4.7 the 'changed' field in the 'users' table has been renamed 'access'.
I have made the necessary alterations and tested briefly with 4.7.2:

<?php
//
//  Show list of (x) last logged on users
//  *************************************
//  See drupal.org/node/44587 - Posted by Sverre
//  If user has no picture will show username instead
//  Includes title attribute in link
//  Tested briefly in Drupal 4.7.2
//  Change '$list_no' to increase / decrase list
//
$list_no = 5;
$sql = "SELECT u.uid, u.name, u.status, u.access, u.picture FROM {users} u WHERE u.status = 1 ORDER BY u.access DESC LIMIT $list_no";
$output = '<div class="item-list"><ul>';
$result = db_query($sql);
while (
$auser = db_fetch_object($result)) {
  if (
$auser->picture) {
   
$showthis = '<img src="/'.$auser->picture.'" />'; // Show Picture
 
} else {
   
$showthis = $auser->name; // Show Text
 
}
 
$output .= "<li>".l($showthis, "user/$auser->uid", array ("title" => "View ".$auser->name."'s profile."), null, null, FALSE, TRUE)."</li>";
}
$output .= "</ul></div>";
print
$output;
?>

Hope this helps.

Likewise for the original snippet

Sverre - August 15, 2006 - 22:35

The same is true for the original snippet at the top of the page:

<?php

//show user pictures ---------------------------
//not tested. Will only show those users who have a picture
global $user;
$count2 = 8; //how many pictures to show, change this value
//
$count = $count2+10; //how many users in total with or without pictures
$co=0;

print
'<TABLE BORDER="1" CELLPADDING="5"  CELLSPACING="10" WIDTH="100%"><TR><TD>';

$result = db_query("SELECT * FROM {users} as u where status=1 ORDER BY access DESC");
  while ((
$user_info = db_fetch_object($result)) & $co<$count) {
   if(
$user_info->uid){
       if(
$user_info->picture){
           if (
$co<$count2){
              print
'<a href="/user/'.$user_info->uid.'">
<img src="/'
.$user_info->picture.'"  hspace=5 ></a>';
$co++;
           }
        }
   }
}
print
'</TD></TR></TABLE>';
//------------------------------------------------------

?>

 
 

Drupal is a registered trademark of Dries Buytaert.