开发者

Counting number of seconds spent on site by specific user and store in mysql

i want to count the number of seconds each user is spending on my page. suppose X user entered the site and he entered at 8 am and leaving at 8:15 am so i want to add this 900 value in that users account assume that user visited several time earlier and 5000 is already in there account so after this visit it should be 5900 and next time when he visits that no of seconds will be added in 5900 .please guide how to do as with javascript we can do this but it wont be stored in mysql . as i n开发者_开发知识库eed to use this values so i want to store in mysql.


Use an ajax call to php web page/service which update your database, it's better if you can store log in and log out time and get the duration spent on site using a query.

This ( http://satoewarna.com/jqsajax/ ) will help you in calling PHP method from javascript.


Since you didn't provide any hint of how is your schema, I would do it like this:

UPDATE my_table SET seconds_spent_so_far = ifnull(seconds_spent_so_far,0) + timediff(session_end,session_start)

session_end and session_start could be fields in your table or variables if your are building your query from php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜