Author Topic: Number of users online  (Read 1496 times)

flyer5

  • Active Member
  • ***
  • Posts: 96
  • Karma: +4/-0
    • North East Nudists
Number of users online
« on: April 04, 2015, 09:13:29 AM »
a fellow etano user asked how to do this...

In home.php
ADD the following block of code  - probably around line 50
Code: [Select]
// Begin count users online
$query="SELECT count(*) FROM `{$dbtable_prefix}online` ";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
$my_stats['online_count']=mysql_result($res,0,0);
// End count users online

Save and Upload

In skins_site/def/home.html
FIND
Code: [Select]
<li>Hi <strong>{tplvars.myself.user}</strong> </li>
CHANGE TO:
Code: [Select]
<li>Hi <strong>{tplvars.myself.user}</strong> - there's <a href="{tplvars.relative_url}search.php?st=online" title="Online Members">{my_stats.online_count}</a> user(s) currently online </li>
Now, when users log in the home page says 'Hi user - theres x users online, and the number is clickable to open the online users page

abo

  • Prime Member
  • ****
  • Posts: 138
  • Karma: +0/-0
Re: Number of users online
« Reply #1 on: April 04, 2015, 09:24:44 AM »
You're the One !
Thank's a lot Flyer5 ;)

flyer5

  • Active Member
  • ***
  • Posts: 96
  • Karma: +4/-0
    • North East Nudists
Re: Number of users online
« Reply #2 on: April 04, 2015, 09:28:08 AM »
Ive noticed it does't update quick enough so changed it, use this block of code instread!

Code: [Select]
// Begin count users online
$query="SELECT count(*) FROM `{$dbtable_prefix}online` WHERE `fk_user_id` <> 0 ";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
$my_stats['online_count']=mysql_result($res,0,0);
// End count users online

abo

  • Prime Member
  • ****
  • Posts: 138
  • Karma: +0/-0
Re: Number of users online
« Reply #3 on: April 04, 2015, 09:38:58 AM »
well done ... thank you again ;)

Mafabel

  • Confirmed Member
  • **
  • Posts: 16
  • Karma: +1/-0
Re: Number of users online
« Reply #4 on: December 22, 2015, 01:24:52 AM »
The number of online users is not visible anywhere on my site after I put the code

webmaster22

  • Confirmed Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Number of users online
« Reply #5 on: March 13, 2016, 05:07:06 AM »
Anyone know how to display registered user count on homepage or wherever I want??

webmaster22

  • Confirmed Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Number of users online
« Reply #6 on: March 14, 2016, 02:13:23 AM »
Anyway , this is for total memebers count, works in home.php , not on index.php for some reason.

In home.php insert:

Code: [Select]
// Begin count users total
$query="SELECT count(*) FROM `{$dbtable_prefix}user_profiles` WHERE `fk_user_id` <> 0 ";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
$my_stats['user_count']=mysql_result($res,0,0);
// End count users total

Then in home.html, wherever you want it:

Code: [Select]
<a href="{tplvars.relative_url}search.php?st=new" title="Total members"> {my_stats.user_count} members</a>

KHDev

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 503
  • Karma: +43/-2
  • Etano Contributor (Skins & Mods)
    • KH Web Development
Re: Number of users online
« Reply #7 on: March 14, 2016, 07:28:29 AM »
The reason you can't get it to work on index.php  is mostly you didn't add this: (usually added near the bottom of the file)

Code: [Select]
$tpl->set_var('my_stats',$my_stats);

home.php already has it declared.

Also, for a  general registered member account i would probably exclude users awaiting deletion just to provide a more accurate number. ;)

Code: [Select]
$query="SELECT count(*) FROM `{$dbtable_prefix}user_profiles` WHERE `fk_user_id` <> 0 AND `del`=0 ";

webmaster22

  • Confirmed Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Number of users online
« Reply #8 on: March 14, 2016, 11:06:19 AM »
Thanks KHDev, thats exactly what I was looking for, total number of activated members on index page!