MyBB Community Forums

Full Version: PHP code to show registered members
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can anyone give me the PHP code to display the number of registered members on a site for the forums.
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users");
$num_rows = $db->num_rows($query); 

echo "$num_rows Rows\n";
Thanks!
Actually a more efficient way of doing it would be:

$query = $db->query("SELECT COUNT(*) as count FROM ".TABLE_PREFIX."users");
$rows = $db->fetch_array($query);
$rows = $rows['count'];

echo $rows;
I need to define what $db is so what should i put exactly?
mysql_

so $db->query[i] would be [i]mysql_query
and $db->fetch_array would be mysql_fetch_array
I tryed that and i got an error:

Call to a member function query() on a non-object
DannyGlass Wrote:I tryed that and i got an error:

Call to a member function query() on a non-object

Ok try this instead


mysql_connect('localhost', 'mysql_username', 'mysql_password');
mysql_select_db('mysql_database');

$query = mysql_query("SELECT COUNT(*) as count FROM mybb_users");
$rows = mysql_fetch_array($query);
$rows = $rows['count'];

echo $rows;

Replace the database connection info with your own, and replace the mybb_ in mybb_users with your MyBB's table prefix.
Worked thanks alot.