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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 195,996
  • Total Topics: 21,327
  • Online today: 232
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 187
  • Total: 187

[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.

JayBachatero

Someone requested this over that SimpleMachines.org.  Wanted to share this with you guys here as well.  I know that there is another way to do this but this way is more efficient since it's taking advantage of the things that are built in SMF.  You can select how many members to display and filter by certain groups.  Enjoy it.


<?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();

$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>
'
$member['avatar']['image'], '<br />
'
$member['link'], '
</td>'
;
}
echo 
'
</tr>
</table>'
;

?>


G6Cad

Great JayBachatero :D

And thank you for sharing this with us here on TP  :)

JPDeni

If you want to use it in a php block or php article, you'll need to remove the first and last lines of the code.

Embrace

Im that somone!


Thanks so much!!!!

Embrace

Table 'kona1.members' doesn't exist
File: /home/content/E/m/b/Embracemy666/html/kon/forum/Sources/Load.php(1806) : eval()'d code(209) : eval()'d code
Line: 15




:(

JPDeni

Add the line


global $db_prefix;


to the beginning of the code.

Embrace

Ok, now I get a box with nothing in it :(... lol, sorry for being so difficult!

JPDeni


Embrace

Of Course

http://www.knightsofnight.com

The code thats in the center PHP block below the images is:

global $db_prefix;
// 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();

$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>
', $member['avatar']['image'], '<br />
', $member['link'], '
</td>';
}
echo '
</tr>
</table>';


Thanks!

JPDeni

Try adding


$memberContext


to the "global" statement.

IOW, change the first line to


global $db_prefix,$memberContext;

This website is proudly hosted on Crocweb Cloud Website Hosting.