BBGameZone.net PBBG Network | BuildingBrowserGames | Top-PBBG
March 10, 2010, 07:23:30 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the Browser-Base Game Zone forums!
 
  Home   Forum   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Viewing Dormant Players  (Read 879 times)
dbest
Level 14
*

Reputation: 1
Offline Offline

Posts: 109


View Profile WWW
« on: November 22, 2009, 09:33:16 AM »

I had to struggle yesterday to figure out how to find dormant players in the game. Dormant players are those who have not logged in for a certain period of days, 30 days in my case. Decided to make a post so that it may help someone in the future and also so that anyone can improve upon my implementation.


Every time a user logins to the game, the userid & the time of login is stored in a table called "logins", as such:

Code:
INSERT INTO logins(id_user,time_login) VALUES ('$user_id',NOW())

The userid & other user details are stored in a table called "users".

To view all users who have not logged during the past 30 days, the following query can be used:

Code:
SELECT user_id FROM users WHERE user_id NOT IN (SELECT id_user FROM logins WHERE DATEDIFF(CURDATE(), time_login) < 30)

This may not be the best way to do it, so anyone with a better way of doing this, please feel free to post their implementation.

Logged

saljutin
Level 18
*

Reputation: 6
Offline Offline

Posts: 189


View Profile
« Reply #1 on: November 22, 2009, 09:49:19 AM »

why do you store every login? do you need to know times for every user for last week?
Logged

dbest
Level 14
*

Reputation: 1
Offline Offline

Posts: 109


View Profile WWW
« Reply #2 on: November 22, 2009, 09:55:58 AM »

good question. main reason is to get rid of dormant users.
Logged

jannesiera
Level 35
**

Reputation: 5
Offline Offline

Posts: 934



View Profile WWW
« Reply #3 on: November 22, 2009, 10:04:19 AM »

why do you store every login? do you need to know times for every user for last week?

It can be handy for statistics Smiley.
Logged

Nox
Level 28
**

Reputation: 10
Offline Offline

Posts: 414



View Profile
« Reply #4 on: November 22, 2009, 10:29:40 AM »

nice... I see it mostly as security-related feature Smiley so many ways to percieve it

I too have login log and beside that I also have lastclick entry so it's possible just
Code:
select * from users where lastclick < NOW() - interval 30 day

edit: of course, ip there, didn't want to get into details
« Last Edit: November 22, 2009, 11:02:28 AM by Nox » Logged

Bookmark worthy: Sirlin.net (game design)

saljutin
Level 18
*

Reputation: 6
Offline Offline

Posts: 189


View Profile
« Reply #5 on: November 22, 2009, 10:49:44 AM »

well for security u should add some IP as well Smiley

but why dont you use something like:

SELECT id_user,MAX(time_login) FROM logins GROUP BY id_user

and then use that in php to compare that time of last login to the one now (time())
I think above query should work, but I didnt test it Smiley
Logged

dbest
Level 14
*

Reputation: 1
Offline Offline

Posts: 109


View Profile WWW
« Reply #6 on: November 22, 2009, 10:59:11 AM »

i have the IP address in my table too, but didnt mention it, as it was not the focus.. Wink

Logged

Mike
Game Owner
Level 13
*

Reputation: 3
Offline Offline

Posts: 97


View Profile WWW
« Reply #7 on: November 22, 2009, 12:06:33 PM »

Ignoring the other reasons to have a seperate login table, to find out which users are dormant why not just store UNIX_TIMESTAMP() into whatever main users table every time they login (or are active?) and then do a search on that (SELECT `id`,`username` FROM `users` WHERE `time_login/time_activity` < UNIX_TIMESTAMP()-(86400*30)Wink. I would have thought that's the best way to find dormant users.
Logged

die4me
Level 16
*

Reputation: 0
Offline Offline

Posts: 139


When life gives you lemons throw them at people


View Profile WWW
« Reply #8 on: November 22, 2009, 12:34:06 PM »

That is a good idea i used that and put a last date active on there profile
Logged

dbest
Level 14
*

Reputation: 1
Offline Offline

Posts: 109


View Profile WWW
« Reply #9 on: November 22, 2009, 12:45:49 PM »

Could do that too ST-Mike. But as you mentioned there are other reasons to create a separate logins table.
Logged

Harkins
Level 21
*

Reputation: 8
Offline Offline

Posts: 238


Coder, blogger, entrepreneur. Open to partnerships


View Profile WWW
« Reply #10 on: November 22, 2009, 01:30:45 PM »

Ignoring the other reasons to have a seperate login table, to find out which users are dormant why not just store UNIX_TIMESTAMP() into whatever main users table every time they login (or are active?) and then do a search on that (SELECT `id`,`username` FROM `users` WHERE `time_login/time_activity` < UNIX_TIMESTAMP()-(86400*30)Wink. I would have thought that's the best way to find dormant users.

No need deal with unix timestamps and multiplication, the standard date and time functions are easier and clearer:

Code:
select id, username from users where last_activity_at >= date_sub(now(), interval 30 day);

Logged

Mike
Game Owner
Level 13
*

Reputation: 3
Offline Offline

Posts: 97


View Profile WWW
« Reply #11 on: November 22, 2009, 03:04:54 PM »

No need deal with unix timestamps and multiplication, the standard date and time functions are easier and clearer:

Code:
select id, username from users where last_activity_at >= date_sub(now(), interval 30 day);

Odd , I always found the timestamp clearer, easier to use and easier to manipulate by far myself. Perhaps it's just a matter of opinion, unless there is a reason why I should not be using the timestamp method.
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
SimplePortal 2.2 © 2008-2009
Valid XHTML 1.0! Valid CSS!