Users Online SQL

Results 1 to 25 of 25
  1. #1
    Account Upgraded | Title Enabled! tomsaundo is offline
    MemberRank
    Sep 2011 Join Date
    Liverpool, UKLocation
    465Posts

    Users Online SQL

    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 by tomsaundo; 05-11-11 at 05:49 PM.


  2. #2
    Live Ocottish Sverlord Joopie is offline
    LegendRank
    Jun 2010 Join Date
    The NetherlandsLocation
    2,773Posts

    Re: Users Online SQL

    PHP Code:
    echo mysql_result(mysql_query('SELECT COUNT(*) FROM `users` WHERE `online` = "1"'), 00).' people online'
    I thought that does the same =3

    But also, You can just download phoenixphp/ubercms, It has also a user online counter in it?

  3. #3
    Account Upgraded | Title Enabled! tomsaundo is offline
    MemberRank
    Sep 2011 Join Date
    Liverpool, UKLocation
    465Posts

    Re: Users Online SQL

    In ubercms you can put %hotelstaus% (i think) and it does it automatically but this is if you want a different one

  4. #4
    Live Ocottish Sverlord Joopie is offline
    LegendRank
    Jun 2010 Join Date
    The NetherlandsLocation
    2,773Posts

    Re: Users Online SQL

    Quote Originally Posted by tomsaundo View Post
    In ubercms you can put %hotelstaus% (i think) and it does it automatically but this is if you want a different one
    That's because it is in a template x.x and already coded into the template system from uber ;/

  5. #5
    Account Upgraded | Title Enabled! tomsaundo is offline
    MemberRank
    Sep 2011 Join Date
    Liverpool, UKLocation
    465Posts

    Re: Users Online SQL

    I know that the point of this release
    ( This is my FIRST sql attempt )

  6. #6
    Eye Eye Capt'n Spheral is offline
    MemberRank
    May 2010 Join Date
    TumptonshireLocation
    2,488Posts

    Re: Users Online SQL

    does this update when users come on and off, or do you have to reload the page?

  7. #7
    Live Ocottish Sverlord Joopie is offline
    LegendRank
    Jun 2010 Join Date
    The NetherlandsLocation
    2,773Posts

    Re: Users Online SQL

    Quote Originally Posted by JohnHearfield View Post
    does this update when users come on and off, or do you have to reload the page?
    What do you thing? php is server side so you must reload or you must use xmlrequest

  8. #8
    Eye Eye Capt'n Spheral is offline
    MemberRank
    May 2010 Join Date
    TumptonshireLocation
    2,488Posts

    Re: Users Online SQL

    so life is refreshing pages to see whos online.

  9. #9
    I don't even know azaidi is offline
    MemberRank
    Apr 2010 Join Date
    the NetherlandsLocation
    2,065Posts

    Re: Users Online SQL

    Nice! I know this isn't a Pro release, but it is great for a beginner.

  10. #10
    [̲̅$̲̅(̲̅1̲̅)̲̅$ ̲̅] leenster is offline
    MemberRank
    May 2008 Join Date
    KanaadaLocation
    992Posts

    Re: Users Online SQL

    If ur using the phoenix emu then i think this query is faster, especially if ur user db is large...

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

  11. #11
    "(still lacks brains)" NoBrain is offline
    MemberRank
    Sep 2011 Join Date
    United KingdomLocation
    2,658Posts

    Re: Users Online SQL

    Quote Originally Posted by leenster View Post
    If ur using the phoenix emu then i think this query is faster, especially if ur user db is large...

    PHP Code:
    SELECT users_online FROM server_status 
    so....
    PHP Code:
    <?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?

  12. #12
    [̲̅$̲̅(̲̅1̲̅)̲̅$ ̲̅] leenster is offline
    MemberRank
    May 2008 Join Date
    KanaadaLocation
    992Posts

    Re: Users Online SQL

    Quote Originally Posted by Jupos View Post
    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";

  13. #13
    "(still lacks brains)" NoBrain is offline
    MemberRank
    Sep 2011 Join Date
    United KingdomLocation
    2,658Posts

    Re: Users Online SQL

    Quote Originally Posted by leenster View Post
    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' ^^

  14. #14
    Account Upgraded | Title Enabled! Muscab is offline
    MemberRank
    Oct 2009 Join Date
    264Posts

    Re: Users Online SQL

    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

  15. #15
    Preparing Riizq is offline
    MemberRank
    Sep 2011 Join Date
    1,829Posts

    Re: Users Online SQL

    Nice, good for begs
    Posted via Mobile Device

  16. #16
    Banned Divide is offline
    BannedRank
    Aug 2011 Join Date
    British CoderLocation
    1,013Posts

    Re: Users Online SQL

    I have a better way:

    Spoiler:
    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 by Divide; 06-11-11 at 02:32 PM.

  17. #17
    "(still lacks brains)" NoBrain is offline
    MemberRank
    Sep 2011 Join Date
    United KingdomLocation
    2,658Posts

    Re: Users Online SQL

    Quote Originally Posted by Divide View Post
    I have a better way:

    Spoiler:
    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 -.-

  18. #18
    Garry's Mod is addictive! Law is offline
    MemberRank
    Dec 2009 Join Date
    NorwayLocation
    993Posts

    Re: Users Online SQL

    Quote Originally Posted by Divide View Post
    I have a better way:

    Spoiler:
    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.

  19. #19
    No, Just no. Matthew is offline
    MemberRank
    Jul 2008 Join Date
    United KingdomLocation
    1,408Posts

    Re: Users Online SQL

    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.

  20. #20
    Alpha Member Danny is offline
    MemberRank
    Oct 2011 Join Date
    My PCLocation
    2,158Posts

    Re: Users Online SQL

    Great, code for a beginner. Great release.

  21. #21
    Retired maritnmine is offline
    MemberRank
    May 2007 Join Date
    North KoreaLocation
    1,103Posts

    Re: Users Online SQL

    Quote Originally Posted by tomsaundo View Post
    Code:
    $getUsers = mysql_query("SELECT * FROM users");


    - Martin

  22. #22
    Account Upgraded | Title Enabled! tomsaundo is offline
    MemberRank
    Sep 2011 Join Date
    Liverpool, UKLocation
    465Posts

    Re: Users Online SQL

    Quote Originally Posted by maritnmine View Post


    - Martin
    Dude I did say I don't know how to do SQL I was messing around so
    Quote Originally Posted by Facebook View Post
    Great, code for a beginner. Great release.
    Thanks at least someone respects that im starting New

  23. #23
    [̲̅$̲̅(̲̅1̲̅)̲̅$ ̲̅] leenster is offline
    MemberRank
    May 2008 Join Date
    KanaadaLocation
    992Posts

    Re: Users Online SQL

    i just go online and count them by hand..... its pretty accurate....
    Last edited by leenster; 10-11-11 at 03:54 AM.

  24. #24

    Re: Users Online SQL

    I looked through this entire thread and absolutely none of this is right. Pheonix stores the array/dictionary/list/(what ever it is) of live connections in the database as positive integer. That is the most reliable online count. For the people that are doing the following:

    Code:
    print mysql_num_rows(mysql_query("SELECT users_online FROM server_status"));
    You are completely wrong. First of all this will always be "1"?

    For the people doing the following:

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

    Code:
    print mysql_num_rows(mysql_query("SELECT * FROM users WHERE online = '1'"));
    ... you are again wrong. This will fetch all the users with an online status of 1. If your vps randomly restarts or the emulator randomly quits it does not restore everyone to online = '0'. Some will still be left as online = '1'.

    With all that being said, I imagine a lot of you (for some odd reason) are all wondering what is the correct way to gather the online count? The most proper way to find the online count in Phoenix is by doing the following:

    Code:
    $hostname = 'localhost';
    $port = 8889;
    $username = 'root';
    $password = 'root';
    
    $database = 'pheonix_database';
    
    mysql_connect("{$hostname:$port}", $username, $passord);
    mysql_select_db($database);
    
    print mysql_result(mysql_query("SELECT ss.users_online FROM server_status ss LIMIT 0,1;"), 0);
    Hopefully you will all learn from this. For the record, I cannot believe we are actually discussing how to get the online count... it truly explains so much. Aim high?

  25. #25
    [̲̅$̲̅(̲̅1̲̅)̲̅$ ̲̅] leenster is offline
    MemberRank
    May 2008 Join Date
    KanaadaLocation
    992Posts

    Re: Users Online SQL

    Quote Originally Posted by EasyHabbo View Post
    I looked through this entire thread and absolutely none of this is right. Pheonix stores the array/dictionary/list/(what ever it is) of live connections in the database as positive integer. That is the most reliable online count. For the people that are doing the following:

    Code:
    print mysql_num_rows(mysql_query("SELECT users_online FROM server_status"));
    You are completely wrong. First of all this will always be "1"?
    the query is right for phoenix..

    PHP Code:
    SELECT users_online,rooms_loaded FROM server_status 


    mysql_num_rows will give u 1 though
    Last edited by leenster; 10-11-11 at 04:32 AM.



Advertisement