Users Online SQL SQL 

Status
Not open for further replies.
Experienced Elementalist
Joined
Sep 17, 2011
Messages
235
Reaction score
30
I know this is no big release but this I'm very proud of because i cant do SQL I was just messing around with the code
This is very helpful if you want it to look different on a certain page not just [[0 user(s) online]]
Now you can have something like [[There is 0 online]]
HERE :
Code:
<?php 
$getOnline = dbquery("SELECT * FROM users WHERE online = '1'");
$Online = mysql_num_rows($getOnline)
?> 
<?php echo $Online; ?> [[add your custom thing such as just ONLINE]]
Also the amount of users registered (Not my work)
Code:
$getUsers = mysql_query("SELECT * FROM users"); 
$users = mysql_num_rows($getUsers); 
?> 
<?php echo $users; ?> [[add your custom thing such as just REGISTERED]]

Don't Flame give your Opinion !
 
Last edited:
In ubercms you can put %hotelstaus% (i think) and it does it automatically but this is if you want a different one
 
does this update when users come on and off, or do you have to reload the page?
 
so life is refreshing pages to see whos online.
 
If ur using the phoenix emu then i think this query is faster, especially if ur user db is large...

PHP:
SELECT users_online FROM server_status

so....
PHP:
<?php 
$getOnline = dbquery("SELECT users_online FROM server_status");
$Online = mysql_num_rows($getOnline)
?> 
<?php echo $Online; ?>
 
If ur using the phoenix emu then i think this query is faster, especially if ur user db is large...

PHP:
SELECT users_online FROM server_status

so....
PHP:
<?php 
$getOnline = dbquery("SELECT users_online FROM server_status");
$Online = mysql_num_rows($getOnline)
?> 
<?php echo $Online; ?>

You do realise that, that gets every user even if they're offline?
 
You do realise that, that gets every user even if they're offline?

yeah i see that i should not have use the rest of his code....

the query is good though

this is how im using it in modcms

$online = $db->Execute("SELECT users_online,rooms_loaded FROM server_status");
$registerd = $db->Execute("SELECT id FROM users");

echo $online->fields['users_online']." User(s) Online | ";
echo $online->fields['rooms_loaded']." Rooms(s) Loaded | ";
echo $registerd->RecordCount()." Registered Users";
 
yeah i see that i should not have use the rest of his code....

the query is good though

this is how im using it in modcms

$online = $db->Execute("SELECT users_online,rooms_loaded FROM server_status");
$registerd = $db->Execute("SELECT id FROM users");

echo $online->fields['users_online']." User(s) Online | ";
echo $online->fields['rooms_loaded']." Rooms(s) Loaded | ";
echo $registerd->RecordCount()." Registered Users";

Oh, I see what you have done.

Basically you have called the $online variable to get the field 'user_online' ^^
 
Nice simple release.

I personally use this.
Code:
<?php

$host = 'localhost';
$port = port;
$user = 'root';
$pass = 'pw';
$db = 'dbname';

mysql_connect("{$host}:{$port}", $user, $pass);
mysql_select_db($db);

print mysql_result(mysql_query("SELECT COUNT(*) FROM users users WHERE users.online = '1';"), 0);

?>

All work's :thumbup:
 
I have a better way:

Code:
$sql = mysql_num_rows(mysql_query("SELECT id FROM users WHERE online = '1'"));
$sql1 = mysql_fetch_assoc(mysql_query("SELECT users_online FROM server_status"));
	if(($sql >= 5) && ($sql1['users_online'] >= 5))
	{
		if($sql == $sql1['users_online'])
		{
		define('%online_count%', $sql.' users online');
		}
		else
		{
		define('%online_count%', $sql1['users_online'].' users online');
		}
	}
	else
	{
	define('%online_count%', '5 users online');
	}



Use <?php echo %online_count%; ?> to show the user count.

P.S. This way, If theres less than 5 users online it will say there is 5 users online. It also means you do not have to have the brackets arround the (s).
 
Last edited:
I have a better way:

Code:
$sql = mysql_num_rows(mysql_query("SELECT id FROM users WHERE online = '1'"));
$sql1 = mysql_fetch_assoc(mysql_query("SELECT users_online FROM server_status"));
	if(($sql >= 5) && ($sql1['users_online'] >= 5))
	{
		if($sql == $sql1['users_online'])
		{
		define('%online_count%', $sql.' users online');
		}
		else
		{
		define('%online_count%', $sql1['users_online'].' users online');
		}
	}
	else
	{
	define('%online_count%', '5 users online');
	}



Use <?php echo %online_count%; ?> to show the user count.

P.S. This way, If theres less than 5 users online it will say there is 5 users online. It also means you do not have to have the brackets arround the (s).

That's just fucking stupid. So much code to do such a little job, your a crack head for thinking that it is a better way -.-
 
I have a better way:

Code:
$sql = mysql_num_rows(mysql_query("SELECT id FROM users WHERE online = '1'"));
$sql1 = mysql_fetch_assoc(mysql_query("SELECT users_online FROM server_status"));
	if(($sql >= 5) && ($sql1['users_online'] >= 5))
	{
		if($sql == $sql1['users_online'])
		{
		define('%online_count%', $sql.' users online');
		}
		else
		{
		define('%online_count%', $sql1['users_online'].' users online');
		}
	}
	else
	{
	define('%online_count%', '5 users online');
	}



Use <?php echo %online_count%; ?> to show the user count.

P.S. This way, If theres less than 5 users online it will say there is 5 users online. It also means you do not have to have the brackets arround the (s).

if($sql1['users_online'] == '1')
{
define('%online_count%', $sql1['users_online'] .' user online');
} else {
define('%online_count%', $sql1['users_online'] .' users online');
}

Isn't that better? Because the only place your going to say "user online" is when it says 1... 1 user online, 2 users online, 3 users online. etc.
 
I have no idea why you're all insisting on posting the same thing over and over but whatever. This is simple PHP... Getting the online count.. alright we get it. Stop posting the same stuff over and over. It's not exactly hard anyways.

If you actually want to post something worth while. Make a script which selects the online count using int from the server_status table, using apc cache the value for 5 minutes then re-query for the value and cache it again.. That would be the best and more efficient method of getting the online count.
 
  • Like
Reactions: Law
Status
Not open for further replies.
Back