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>';
?>
Great JayBachatero :D
And thank you for sharing this with us here on TP :)
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.
Im that somone!
Thanks so much!!!!
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
:(
Add the line
global $db_prefix;
to the beginning of the code.
Ok, now I get a box with nothing in it :(... lol, sorry for being so difficult!
Can I see the page?
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!
Try adding
$memberContext
to the "global" statement.
IOW, change the first line to
global $db_prefix,$memberContext;
Wonderful!
now just to make sure everyone has an avatar!
Thanks alot JPDeni!
I'm glad I could help.
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.
Thanks Jay!
Edited the code in the first post for the globals.
:( Is there a way for it to display an image if the user does not have an avatar, it looks funny without it~
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>';
?>
You rock!!
see it in action at knightsofnight.com :)
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!
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.
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
Remove the php tags..
Delete the first and last line of the script:
<?php
and
?>
thanks! another thing, guys. what if i want the avatars to be resized to 65px x 65px? can you please show me what and where to add this?
Thats for a different topic, and is a question for SMF..
But, Admin > Forum/Attachments and Avatars > Avatar Settings
is where you can find the options for avatars.
Ignore that.. I just realised you were refering to the avatars for this snippit :buck2:
The avatar for this snippet will use the one from the members context. It will be controlled by SMF's settings for avatars. If you put in the custom avatar you'll need to size that one to your needed settings.
ichbin,
i'm using the dilbermc theme and one thing i noticed was that eventhough i specified 65px by 65 px for avatar size in smf, the theme seems to be resizing it to a smaller version..
Then you should probably seek help from the theme author if his theme is doing that.
Quote from: alving on October 24, 2007, 09:36:58 AM
thanks! another thing, guys. what if i want the avatars to be resized to 65px x 65px? can you please show me what and where to add this?
', empty($member['avatar']['image']) ? '<img src="' . $avatarImage . '" />' : $member['avatar']['image'], '<br />
', empty($member['avatar']['image']) ? '<img src="' . $avatarImage . '" />' : str_replace('class="avatar"', 'width="65" height="65" class="avatar"', $member['avatar']['image']), '<br />
Hi,
I have this great block but it's also adding the latest two members, so if I limit it to seven, it will display nine (seven random and the two latest members).
I have the tops stats block and the problem is linked to it as when I turn this block off my random members block returns to the correct number.
My top stats block code is below, can anyone help?
global $db_prefix, $memberContext;
$count = 2;
$users = array();
$request = db_query("
SELECT ID_MEMBER FROM {$db_prefix}members WHERE is_activated = 1 ORDER BY ID_MEMBER DESC LIMIT ".$count, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request)) {
$users[] = intval($row['ID_MEMBER']);
}
loadMemberData($users);
echo'<table border="1" width="100%" id="table1" cellpadding="2" style="border-collapse: collapse">
<tr><td bgcolor="#FF9900" width="100"><font color="#FFFFFF" face="Verdana" size="2"><b>Newest Members</b></font></td><td bgcolor="#660066" width="150"><font color="#FFFFFF" face="Verdana" size="2"><b>Top 10 Posters</b></font></td><td bgcolor="#336699" width="150"><font color="#FFFFFF" face="Verdana" size="2"><b>This Weeks Top Posters</b></font></td><td bgcolor="#00CC33" width="150"><font color="#FFFFFF" face="Verdana" size="2"><b>This Months Birthdays</b></font></td><td bgcolor="#660066" width="150"><font color="#FFFFFF" face="Verdana" size="2"><b>Top Gamers</b></font></td></tr><tr>
<td>';
$i = 0;
foreach($users as $user_id) {
if ($i > 0) echo '<hr>';
$i++;
loadMemberContext($user_id);
if (!empty($memberContext[$user_id]['avatar']['image']))
echo '<div align="center">'.$memberContext[$user_id]['avatar']['image'].'<BR>'.$memberContext[$user_id]['link'].'</div>';
else
echo '<div align="center"><img src="http://www.rewindlancs.com/forum/images/noava.gif" height=80 widh=80><BR><BR>'.$memberContext[$user_id]['link'].'</div>';
}
$numberofposters = 10; // You can change this to however many you want
require_once "SSI.php";
$top_posters = ssi_topPoster($numberofposters, "return");
echo'</td><td>';
foreach ($top_posters as $poster)
{
echo $poster['link'] , ' (', $poster['posts'] , ')<br />';
}
echo'</td><td>';
global $db_prefix, $scripturl;
$count= array();
$poster_number = array();
$query = db_query(
"SELECT realName, {$db_prefix}messages.ID_MEMBER, ID_GROUP
FROM {$db_prefix}members
JOIN {$db_prefix}messages
ON {$db_prefix}members.ID_MEMBER = {$db_prefix}messages.ID_MEMBER
ORDER BY posterTime DESC
LIMIT 100", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($query))
{
if (!isset($count[$row['realName']]))
$count[$row['realName']] = 0;
++$count[$row['realName']];
$poster_number[$row['realName']] = $row['ID_MEMBER'];
}
$random = array_rand($count, count($count));
echo '<div style="text-align: center">';
foreach ($random as $value)
{
$fsize = $count[$value] + 7;
if ($fsize > 13)
$fsize = 13;
elseif ($fsize < 7)
$fsize = 7;
$name = str_replace(" ",'·',$value);
echo '<a class="normaltext" href="' . $scripturl . '?action=profile;u=' . $poster_number[$value] . '">
<span style="font-size:' . $fsize . 'pt;">' . $name . '</span></a> ';
}
echo '</div></td><td>';
global $db_prefix, $scripturl;
echo '
<div style="padding: 4px; font-weight: bold;">';
// echo $title;
echo '
</div>
<div class="windowbg" style="padding: 4px; ">';
$month = date('m');
$month_number = '-' . $month . '-';
$query = db_query(
"SELECT ID_MEMBER, memberName, birthdate
FROM {$db_prefix}members
WHERE birthdate LIKE '%$month_number%'
AND birthdate NOT LIKE '0001-01-01'
ORDER BY memberName", __FILE__, __LINE__);
if(db_affected_rows() != 0)
{
$birthdays = array();
$member = array();
while ($row = mysql_fetch_assoc($query))
{
$day = substr($row['birthdate'],8,2);
$birthdays[$row['memberName']] = $day;
$member[$row['memberName']] = $row['ID_MEMBER'];
}
asort($birthdays);
foreach ($birthdays as $key => $value)
{
echo '<a class="normaltext" href="' . $scripturl . '?action=profile;u=' . $member[$key] . '">' . $key . '</a> (' . $value . '.' . $month . ')<br />';
}
}
else
echo 'No birthdays this month';
echo'</td><td>';
//-------START-------------
/*
|----------------------------------
SMF ARCADE SCROLLING CHAMPS BLOCK for SMFARCADE V2
by Eric Lawson
|----------------------------------
Made for TinyPortal and SMF forum
*/
//Upload a pic called arcade_block.gif (you can use you own gif - just name it arcade_block.gif)
//to your Themes/<themename>/images/ folder
// -- SETUP EDITS ---
$no = 10; //number of top players to show
// --LANGUAGE EDITS --
$txtplay = "The Top Players"; // change "The Top Players" to your language
$txtwin = "Number Of Wins :";// change "Number Of Wins :" to your language
$txtlate = "Latest High Score by ";// change "Latest High Score set by" to your language
$txtwit = "with ";// change "with" to your language
$txton = "on ";// change "on" to your language
global $scripturl,$sourcedir,$boardurl,$db_prefix,$modSettings;
require_once($sourcedir.'/ArcadeStats.php');
//Get newest champ or die
$sql = "SELECT game.ID_GAME, game.gameName, game.thumbnail, game.gameDirectory,
IFNULL(mem.ID_MEMBER, 0) AS ID_MEMBER, IFNULL(mem.realName,'') AS realName, score.score
FROM {$db_prefix}arcade_scores AS score
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = score.ID_MEMBER)
JOIN {$db_prefix}arcade_games AS game ON (game.ID_GAME = score.ID_GAME)
ORDER BY `championFrom` DESC
LIMIT 0,1";
if(!($result = db_query($sql,__FILE__,__LINE__)))
{
die("Could not get the newest champ");
}
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
if(isset($row['gameDirectory']))
{
$row['gameDirectory']=$row['gameDirectory']."/";
}
//newest champ details
$playerid = $row['ID_MEMBER'];
$player = $row['realName'];
$game_id = $row['ID_GAME'];
$game_name = $row['gameName'];
$score = $row['score'];
$game_pic = $modSettings['gamesUrl'].$row['gameDirectory'].$row['thumbnail'];
$bp=ArcadeStats_BestPlayers($no);
$score_poss=0; //players position
echo '
<script type="text/javascript">';
/***********************************************
* Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
//Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
//Specify marquee scroll speed (larger is faster 1-10)
//Pause marquee onMousever (0=no. 1=yes)?
echo '
var delayb4scrollx=2000
var marqueespeedx=1
var pauseitx=1';
////NO NEED TO EDIT BELOW THIS LINE////////////
echo '
var copyspeedx=marqueespeedx
var pausespeedx=(pauseitx==0)? copyspeedx: 0
var actualheightx=\'\'';
echo '
function scrollmarqueex(){
if (parseInt(cross_marqueex.style.top)>(actualheightx*(-1)+8))
cross_marqueex.style.top=parseInt(cross_marqueex.style.top)-copyspeedx+"px"
else
cross_marqueex.style.top=parseInt(marqueeheightx)+8+"px"
}
function initializemarqueex(){
cross_marqueex=document.getElementById("vmarqueex")
cross_marqueex.style.top=0
marqueeheightx=document.getElementById("marqueecontainerx").offsetHeight
actualheightx=cross_marqueex.offsetHeight
if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){
cross_marqueex.style.height=marqueeheightx+"px"
cross_marqueex.style.overflow="scroll"
return
}
setTimeout(\'lefttime=setInterval("scrollmarqueex()",30)\', delayb4scrollx)
}
if (window.addEventListener)
window.addEventListener("load", initializemarqueex, false)
else if (window.attachEvent)
window.attachEvent("onload", initializemarqueex)
else if (document.getElementById)
window.onload=initializemarqueex
</script>';
echo '<table width="100%">
<tr>
<td align="center">
</td>
</tr>
</table>
<div id="marqueecontainerx" style="position: relative; width: 95%; height:200px; overflow: hidden; border: 0px; padding: 2px; padding-left: 4px;" onmouseover="copyspeedx=pausespeedx" onmouseout="copyspeedx=marqueespeedx">
<div id="vmarqueex" style="position: absolute; width: 98%;">
<div align="center">
<a href="',$scripturl,'?action=arcade;sa=play;game=',$game_id,'"><img src="',$game_pic,'" border="0" alt="',$game_name,'" width="60" height="60"/></a>
<br />',$txtlate,'<br />
<a href="',$scripturl,'?action=profile;u=',$playerid,'">',$player,'</a>
<br/>',$txtwit,' ',$score,' ',$txton,'<br />',$game_name,'
<br />------------------<br />',$txtplay,'<br /><br />';
foreach ($bp as $out)
{
$score_poss++;
echo '',$score_poss,' - ',$out['link'],'<br />',$txtwin,' ',$out['champions'],'
<br /><br />';
};
echo '</div>
</div>
</div>';
//---------END--------------
echo'</td></tr>
</table>';
and my random members code is: -
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 = 'http://rewindlancs.com/forum/images/noava.gif';
$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 ALIGN="center">
<tr>';
foreach ($memberContext as $member)
{
echo '
<td><center>
', empty($member['avatar']['image']) ? '<img src="' . $avatarImage . '" />' : str_replace('class="avatar"', 'width="65" height="65" class="avatar"', $member['avatar']['image']), '<br />
', $member['link'], '
</center></td>';
}
echo '
</tr>
</table>';
Regards,
Wilsy.
Shared variables between the two scripts? Second script inherits the value left behind by the first?
It's the fact that the $memberContext variable is global in both blocks, without being cleared. You could try adding
$memberContext = array();
at the end of your first block, after everything is printed out.
JPDeni is a genius - thank you so much!
Regards,
Wilsy.
i tried using this code that displays a generic image for members without avatar but there are times that the generic image is not being displayed for some members without avatar.. any help please..
I was curious abou thow to change it to display people that haven't not logged in within a certain amount of days, Is there a way to do this?
i'm trying to get random members from a particular post group, but everytime i put in the group number, the script displays nothing.. i dont know what i'm doing wrong..
help please. thanks in advance
Change
$group_clause = empty($groups) ? '1' : 'ID_GROUP IN(' . implode(',', $groups) . ')';
to
$group_clause = empty($groups) ? '1' : 'ID_POST_GROUP IN(' . implode(',', $groups) . ')';
thanks jay! it's working now..
Any chance to a way to control how many lines in the table? I would like to have the block without the scrolling. Something like a 3X2 table in the block. Can someone help with this?
global $db_prefix, $memberContext;
// How many members we want?
$members_limit = 6;
// How many to display per row? Should be a factor of the $members_limit
$per_row = 3;
// 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 = 'http://rewindlancs.com/forum/images/noava.gif';
$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);
$display = 0;
echo '
<table ALIGN="center">
<tr>';
foreach ($memberContext as $member)
{
++$display;
echo '
<td><center>
', empty($member['avatar']['image']) ? '<img src="' . $avatarImage . '" />' : str_replace('class="avatar"', 'width="65" height="65" class="avatar"', $member['avatar']['image']), '<br />
', $member['link'], '
</center></td>';
if ($display == $per_row) {
echo '
</tr>
<tr>
';
$display = 0;
}
}
echo '
</tr>
</table>';
I've added another variable $per_row that you can set to make your table.
I didn't test it, but I'm pretty sure it wil work.
Wow! That was fast! Works like a charm, but it counts 1 more user: if you set to 5 it will show 6... no problem at all.
Can I ask you a little more help? Theres almost the same block for the newest users, you asked me about what I want and this is really what I would like to have for the newest block.
http://www.tinyportal.net/index.php/topic,7737.140.html
That works GREAT!!!
http://www.greatplainsriders.com/smf/index.php?action=forum