Jump to content

Tracking User Activity?


balkan7

Recommended Posts

I need help to create code for user bar activity, i have in datebase this fields:

user_id, user_joined, user_lastactivity user_status...., so need help with explame because i wanna get user bar activity like:

 

username: admin

activity: 80%

Link to comment
Share on other sites

you could create another table called UserActivity and have fields UserID, activity and insert a new records on activites from that you can count the total of number of records we're call that TotalActivity and then count the records where UserID equals the users id we're call that UserActivity

 

then

echo "$UserName %".($UserActivity / $TotalActivity)* 100;

 

Link to comment
Share on other sites

Soryy but i cant undestand again, we got 4 fields in datebase for checking user activity, -> UserId, UserJoined, UserLastvisit and UserActivity.

 

so we begin when user is logout in datebase we iserting:

$time = time();
$result = mysql_query("INSERT INTO users (UserId, UserLastvisit, UserActivity) values ("", "$time", "$time")");

here we got same time for last visit and acitvity, how can count... if you wanna explame me with code.

Link to comment
Share on other sites

i cant find solution for this :(, also i got second table (online), -> online_user, online_ip and online_lastactive so maybe here must to be field activity but still need help when user logout what i need to write to field activity on datebase online?

 

soryy i need this one...

Link to comment
Share on other sites

what part do you not understand ?

 

you could create another table called UserActivity and have fields UserID, activity and insert a new records on activites from that you can count the total of number of records we're call that TotalActivity and then count the records where UserID equals the users id we're call that UserActivity

 

then

echo "$UserName %".($UserActivity / $TotalActivity)* 100;

 

Link to comment
Share on other sites

i have to try with this options but i get this result: Activity: 32900% where i wrong, how can i get true result ?

 

code is:

<?php
$timenow = time();
$minus = $timenow - $data['user_lastvisit'];
$options = number_format($timenow / $minus)*100;
?>

 

 

Link to comment
Share on other sites

What you have tried makes no logical sense!

 

You are basically working out how long ago the last activity was. and using that to get a percentage of use! :S .. that can't work!

 

you can't just used the existing data.. you need more.. hence building another table etc..

 

Please read my last post.. what part doesn't make sense ?

 

Link to comment
Share on other sites

i agree with you MadTechie, ok i create new table (activity with those fields: user_id, user_ip and user_activity) so i'm really confused when user logout what need inserting on field user_activity, when user again active delete old activity?, also on table users update last visit, i need just simple explame with code, insert in table activity and calculating but i cant get it :(

Link to comment
Share on other sites

okay when user does something, system inserts a records into UserActivity table..

 

for example, (ignore , curtime() if your not using a datestamp.. personally i would)

user 10: logs in,

system: adds a record (10, "logs in", curtime())

user 10: logs out,

system: adds a record (10, "logs out", curtime())

user 11: logs in,

system: adds a record (11, "logs in", curtime())

user 10: logs in,

system: adds a record (10, "logs in, curtime()")

user 10: logs out,

system: adds a record (10, "logs out", curtime())

user 11: logs out,

system: adds a record (11, "logs out", curtime())

 

SELECT count(*) as UA FROM UserActivity

$ROW['UA'] = 6

Okay thats 6 records in UserActivity

 

SELECT count(*) as UA FROM UserActivity WHERE user_id = 11

$ROW['UA'] = 2

2 for User 11 and

SELECT count(*) as UA FROM UserActivity WHERE user_id = 10

$ROW['UA'] = 4

4 for user 10

 

so

($UserActivity / $TotalActivity)* 100;

User 10 Activity: (4 / 6)* 100; = 66.666

User 11 Activity: (2 / 6)* 100; = 33.333

okay a little tweak

round(($UserActivity / $TotalActivity)* 100);

 

which is

User 10 Activity: 66%

User 11 Activity: 33%

 

Last part would be adding a date range and would be an idea to add a clean up routine to remove out dated records.. but you should get the idea now

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.