TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 01, 2024, 02:26:18 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,174
  • Total Topics: 21,220
  • Online today: 167
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 110
  • Total: 110

Random User Block

Started by Xarcell, November 08, 2005, 09:25:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Embrace

Any way to get somthing like this that displays random members avatars with a link to the profile of the member?

I want somthing like phpizabi has :)

http://demo.phpizabi.net/

check the vary bottom of that page


Thanks,
Embrace


phfire

How do I filter out those members without avatars? Display only those with avatars. May I know the code please. Thanks.

JPDeni


phfire

#24
this one

global $db_prefix, $memberContext;

// How many members we want?
$members_limit = 7;
// Just special groups get to be part of the block.
// To select Admins and moderators would be like $groups = array(1, 2);
$groups = array();
// Avatar images.
$avatarImage = '';

$group_clause = empty($groups) ? '1' : 'ID_GROUP IN(' . implode(',', $groups) . ')';

// Lets get the ID's of the members we want.
$request = db_query("
SELECT ID_MEMBER
FROM {$db_prefix}members
WHERE $group_clause
ORDER BY RAND()
LIMIT $members_limit", __FILE__, __LINE__);
$members = array();
while ($row = mysql_fetch_assoc($request))
$members[] = $row['ID_MEMBER'];
mysql_free_result($request);

// Load the data for these members.
loadMemberData($members);

// Now get the context.
foreach ($members as $member)
loadMemberContext($member);

echo '
<table valign="middle" align="center">
<tr>';
foreach ($memberContext as $member)
{
echo '
<td>
', empty($member['avatar']['image']) ? '<img src="no avatar pic" />' : $member['avatar']['image'], '<br />
', $member['link'], '
</td>';
}
echo '
</tr>
</table>';


EDIT: placed the code in a code box for you... ken

JPDeni

It's a whole lot easier to read code if you use the "code" tags. You can access them by clicking the button that has a # on it.

To only show users that have avatars, change


$request = db_query("
   SELECT ID_MEMBER
   FROM {$db_prefix}members
   WHERE $group_clause
   ORDER BY RAND()
   LIMIT $members_limit", __FILE__, __LINE__);


to


$request = db_query("
   SELECT ID_MEMBER
   FROM {$db_prefix}members
   WHERE $group_clause
   AND  LENGTH( `avatar` ) >0
   ORDER BY RAND()
   LIMIT $members_limit", __FILE__, __LINE__);

phfire

oh ok..sorry for the dirty post. i'll do it right next time. thanks for helping me out! :)

Ken.

Quote from: phfire on February 10, 2008, 01:43:59 PM
oh ok..sorry for the dirty post. i'll do it right next time. thanks for helping me out! :)

phfire, its fixed for you now but for future reference you can do corrections to your post be clicking the 'Modify' link inside the post in question.  :)
" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.