MyBB Community Forums

Full Version: Whos on index??
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, i am wondering if anone can give me a code so that on the index page of my site (forums located /forums ) it shows who is on them.


Thank you.
Hello

In your page add the following

<?php
	//Connect to mybb db
	mysql_connect("localhost", "username", "password") or die("Could not connect to MySQL");
	mysql_select_db("dbname") or die("Could not connect to MySQL");
	
	$timesearch = time() - (15*60);
	$query = mysql_query("
		SELECT DISTINCT s.sid, s.uid, s.time,  u.username, u.invisible, u.usergroup, u.displaygroup
		FROM mybb_sessions s
		LEFT JOIN mybb_users u ON (s.uid=u.uid)
		WHERE s.time>'$timesearch'
		ORDER BY s.time DESC
	");
	$list = '';
	while($fetch = mysql_fetch_array($query))
	{
		if($fetch['invisible'] != "yes")
		{
			$list .= "<a href=\"member.php?action=profile&uid=".$fetch['uid']."\">".$fetch['username']."</a>";
		}
	}
	echo $list;
?>

You need to change the db connection db selection parameters according to your mybb db.
Thanks, would this show whos on the forum or who is on the index page of my site (off the forum) It looks like to me whos online on the forum but that will do. Thank you.