balkan7 Posted July 15, 2008 Share Posted July 15, 2008 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% Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/ Share on other sites More sharing options...
cooldude832 Posted July 15, 2008 Share Posted July 15, 2008 create some sort of mathmatical formula for your "activity" and then come back with a question Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591077 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591078 Share on other sites More sharing options...
balkan7 Posted July 15, 2008 Author Share Posted July 15, 2008 yes but how can count script whitout user_lastacivity and time now? Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591082 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 add an extra field with a time&date stamp in the UserActivity table Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591088 Share on other sites More sharing options...
balkan7 Posted July 15, 2008 Author Share Posted July 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591108 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 here we got same time for last visit and acitvity, how can count... if you wanna explame me with code. LOL, na.. i am not going to write it for you.. read my first post.. it explains about creating another table.. Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591112 Share on other sites More sharing options...
balkan7 Posted July 15, 2008 Author Share Posted July 15, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591118 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591120 Share on other sites More sharing options...
balkan7 Posted July 16, 2008 Author Share Posted July 16, 2008 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591634 Share on other sites More sharing options...
MadTechie Posted July 16, 2008 Share Posted July 16, 2008 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591646 Share on other sites More sharing options...
balkan7 Posted July 16, 2008 Author Share Posted July 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591660 Share on other sites More sharing options...
MadTechie Posted July 16, 2008 Share Posted July 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591683 Share on other sites More sharing options...
balkan7 Posted July 16, 2008 Author Share Posted July 16, 2008 thank you i will try! Quote Link to comment https://forums.phpfreaks.com/topic/114929-tracking-user-activity/#findComment-591698 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.