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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 206
  • Total: 206

[Block] Random User Block - New

Started by JayBachatero, October 22, 2007, 07:11:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Embrace

Wonderful!

now just to make sure everyone has an avatar!

Thanks alot JPDeni!

JPDeni


JayBachatero

Thanks for pointing out the needing to global those vars.  I did this using SSI.php so didn't need to globalize them.  Thought it would be the same for TP since it uses SSI.php :P.

IchBin

Thanks Jay!

Edited the code in the first post for the globals.

Embrace

:( Is there a way for it to display an image if the user does not have an avatar, it looks funny without it~

JayBachatero

Ok use this.  Supply the image url at the top for the missing avatar.


<?php
global $db_prefix$memberContext;

// How many members we want?
$members_limit 5;
// 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>
<tr>'
;
foreach (
$memberContext as $member)
{
echo '
<td>
'
, empty($member['avatar']['image']) ? '<img src="' $avatarImage '" />' $member['avatar']['image'], '<br />
'
$member['link'], '
</td>'
;
}
echo 
'
</tr>
</table>'
;

?>


Embrace


texasflats

I love it, thanks so much..

Would it be possible to add the users number of post, and most recent post?

Thanks again for this, just what I needed!

JPDeni

Number of posts would just be $member['posts'] in the printout section.

The most recent post would require a whole lot more coding and calls to the database.

alving

i'm getting this error

Parse error: syntax error, unexpected '<' in /hsphere/local/home/db/dbf.com/smf/Sources/Load.php(1737) : eval()'d code(35) : eval()'d code on line 1

This website is proudly hosted on Crocweb Cloud Website Hosting.