Displaying the newest users who have pictures

scarer - August 17, 2007 - 05:00

Hi,

I was wondering if anyone could help me out on how to complete this block:

<?php

   
//This block show pictures of the newest users to join myQCA

    //get the user with the highest uid

    //store this amount in a variable
    //$highest_uid = $uid;
  

   
for (i =0; i < 3; i ++)
    {
       
$display_uid = $highest_uid - i;
       
//display the user with the uid equal to $display_uid with their avatar and nickname as a link to their //profile

   
}
?>

I basically want to get the user id that's the highest and then display the other recent users with their photo and displayname as a link.

I am not very good with the drupal API yet. Had a good look through the user module but couldn't seem to find what I was looking for.

Any help would be great.

Cheers,

Sarah

sorry did some incorrect stuff

scarer - August 17, 2007 - 05:15

<?php

   
//This block show pictures of the newest users to join myQCA
    //Author: Sarah Vardy
    //Date: 17-08-07

    //get the user with the highest uid

    //store this amount in a variable
   
$highest_uid = 50;

    for (
$i = 0; $i < 3; $i ++)
    {
        
$display_uid = $highest_uid - $i;
       
//display the user with the uid equal to $display_uid with their avatar and nickname as a link to their //profile
        
print($display_uid );

    }
 


?>

Hi - try something like this...

gbear - August 17, 2007 - 06:00

<?php
//get last 3 users with pictures
$getSql = "SELECT u.uid FROM {users} u WHERE u.picture != '' ORDER BY u.uid DESC LIMIT 0, 3";
$result = db_query(db_rewrite_sql($getSql));

$output = '<div id="latestmembers">';
while (
$account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));
  
$output .= theme('user_picture', $account);
  
$output .= l($account->name, 'user/'.$account->uid);
}
$output .= '</div>';

print
$output;
?>

thanks gbear

scarer - August 19, 2007 - 23:38

thanks gbear, that worked great!

cheers,

sarah

one question

scarer - August 20, 2007 - 00:00

one question though... the user pictures are displaying on the far right and when i try to format them they don't move... any suggestions?

cheers,

sarah

Firebug

gbear - August 20, 2007 - 22:18

Just a CSS issue. I think those are wrapped in a class called picture - can just restyle that:

.picture {
float:left;
}

Download firebug for firefox, use the inspect function to locate the CSS styles that are already defined that you can hook into and write your own css for.

hi gbear

scarer - August 20, 2007 - 23:27

thanks for that.

i modified the style sheet like this so it doesn't interfere with the display of the other images on the site:

/* custom block for newest members */
#latestmembers
{
float: left;
}

#latestmembers .picture
{
float:left;
}
/* end custom block for newest members */

thanks for your help!

sarah :)

Little help to get a custom field in the output

weaponx - December 14, 2008 - 11:29

Hi

gbear your script really helped me. I hope someone can point me in the right direction.

<?php
$getSql
= "SELECT users.uid, users_roles.rid, profile_values.value
FROM users
LEFT JOIN users_roles ON users.uid = users_roles.uid
LEFT JOIN profile_values ON users.uid = profile_values.uid
WHERE users.picture != ''
AND users_roles.rid =4
AND profile_values.fid =1
ORDER BY users.name"
;

$result = db_query(db_rewrite_sql($getSql));

$output = '<div id="latestmembers">';
while (
$account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));
  
$output .= '<center>';
  
$output .= l($account->name, 'user/'.$account->uid);
  
$output .= theme('user_picture', $account);
  
$output .= '</center><hr style="width:90%" />';
}
$output .= '</div>';

print
$output;
?>

I retrieve a value in my query profile_values.value how can i output that value as well?

In advance thx.

---------

Edit i figured it out. It was very simple:

<?php
$getSql
= "SELECT users.uid, users_roles.rid, profile_values.value
FROM users
LEFT JOIN users_roles ON users.uid = users_roles.uid
LEFT JOIN profile_values ON users.uid = profile_values.uid
WHERE users.picture != ''
AND users_roles.rid =3
AND profile_values.fid =1
ORDER BY users.name"
;

$result = db_query(db_rewrite_sql($getSql));

$output = '<div id="parents">';
while (
$account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));

  
$output .= '<table><tr><td>';
  
$output .= l($account->name, 'user/'.$account->uid);
  
$output .= theme('user_picture', $account);
  
$output .= '</td><td valign="top"><b>Om os:</b><br>';
  
$output .= $account->profile_about;
  
$output .= '</td></tr></table>';
}
$output .= '</div>';

print
$output;
?>

You can display all fields you wish by using the user_load array.

$output .= $account->profile_about;

will display a custom field with the id profile_about

 
 

Drupal is a registered trademark of Dries Buytaert.