MyBB Community Forums

Full Version: Random Members on portal
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'd like to have a section in the portal that shows 3 random members (Name and Avatar; no avatar available, then show a "no avatar" avatar made by me).

I know how to format the HTML and such. How would I go about the coding of being able to show these random members?

Thanks.
Still been trying to figure this out with no success. Anyone have any ideas?
You would have to use php.

First count the max number of users in the db
second make 3 random values between 1 and the max # of users
third select the row of the user
fourth output the user and details

You should be able to find the users table in mybb_users

to make sure it doesnt screw up if users have been deleted: when you generate a random number check if there is a user that exists with that id before outputting Toungue
Here, I've made a quick script:

<?
require "./global.php";

function main() {
global $db;

$count = mysql_num_rows($db->query("SELECT * FROM ".TABLE_PREFIX."users"));

$rand1 = rand(1, $count);
$rand2 = rand(1, $count);
$rand3 = rand(1, $count);

$rand1out = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid = \"".$rand1."\"");
$rand2out = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid = \"".$rand2."\"");
$rand3out = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid = \"".$rand3."\"");

$random1 = mysql_fetch_row($rand1out);
$random2 = mysql_fetch_row($rand2out);
$random3 = mysql_fetch_row($rand3out);
$replacev = array("./", "../");

$random1av = str_replace($replacev, "", $random1[7]);
$random2av = str_replace($replacev, "", $random2[7]);
$random3av = str_replace($replacev, "", $random3[7]);

if($random1[7] == NULL || $random1[7] == "") { $random1av = "No Avatar"; }
else { $random1av = "<img src=\"./".$random1av."\"></img>"; }
if($random2[7] == NULL || $random2[7] == "") { $random2av = "No Avatar"; }
else { $random2av = "<img src=\"./".$random2av."\"></img>"; }
if($random3[7] == NULL || $random3[7] == "") { $random3av = "No Avatar"; }
else { $random3av = "<img src=\"./".$random3av."\"></img>"; }





echo stripslashes($random1[1])."<br />".$random1av."<br /><br />";
echo stripslashes($random2[1])."<br />".$random2av."<br /><br />";
echo stripslashes($random3[1])."<br />".$random3av."<br /><br />";
}

main();

?>



Example: http://rct3x.co.uk/myBB2/3randusers.php


@leejeffery, in the script above, it will just wont return anything, if the user doesnt exist
Make it so duplicate users are accounted for!