MyBB Community Forums

Full Version: Display Member Count on Homepage - code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
What's the php code that displays the number of members?
You could do it like this:
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."users");
$member_num = mysql_num_rows($query);

The variable $member_num would give you the number of members.
DrPoodle Wrote:You could do it like this:
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."users");
$member_num = mysql_num_rows($query);

The variable $member_num would give you the number of members.

More efficient would be:

$query = mysql_query("SELECT COUNT(*) as total FROM mybb_users");
$temp = mysql_fetch_array($query);
$member_num = $temp['total'];
Shouldn't this be in code modification?
DennisTT Wrote:
DrPoodle Wrote:You could do it like this:
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."users");
$member_num = mysql_num_rows($query);

The variable $member_num would give you the number of members.

More efficient would be:

$query = mysql_query("SELECT COUNT(*) as total FROM mybb_users");
$temp = mysql_fetch_array($query);
$member_num = $temp['total'];
what if the prefix wasn't "mybb_" though...
Then you change it to ".TABLE_PREFIX." Wink
Still if it were to be included inside mybb files you should use the mysql class, and if it is not. TABLE_PREFIX won't be valid anyways.
Is there anyway to make this also return the name of the newest member as well?

EDIT:
The number of users online on the forums may also be handy
Sure.
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."users" ORDER BY uid DESC LIMIT 0,1);
$array = mysql_fetch_array($query);
$newest_member = $array['username'];
DrPoodle Wrote:Sure.
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."users" ORDER BY uid DESC LIMIT 0,1);
$array = mysql_fetch_array($query);
$newest_member = $array['username'];
Thanks, does that just show the newest member? If so what about the online users?
CraKteR Wrote:Still if it were to be included inside mybb files you should use the mysql class, and if it is not. TABLE_PREFIX won't be valid anyways.

That's exactly why I used mybb_ instead of TABLE_PREFIX as you had used mysql_query, I assumed you were giving code for use on pages where the MyBB global.php is not included.

However, if global.php is included, you can easily retrieve the statistics and the newest member using the cache.
Pages: 1 2