简体   繁体   English

PHP MySQL的,如何获得总时间?

[英]php mysql, how to get total time?

i have a table that has users, the pages that they visited , session id and time they spent on each page. 我有一个表,其中包含用户,他们访问的页面,会话ID和他们在每个页面上花费的时间。

session_id | talentnum    | page_name    | time
008873e0   | user1        | test.php     | 1311630222
008873e0   | user1        | test.php     | 1311630215
008873e0   | user1        | index.php    | 1311630222
008873e3   | user2        | test.php     | 1311630216
008873e3   | user2        | index.php    | 1311895032

how to find ouy how much time a user spent on each session 如何查找用户每次会话花费了多少时间

i think i should find how much the user spent on each page in a session then add the time?? 我想我应该找到用户在会话中的每个页面上花费了多少,然后增加了时间? i'm a bit confuze 我有点糊涂

edit. 编辑。 the time is the time() when they enter that page 时间是他们进入该页面时的time()

any ideas? 有任何想法吗? thanks 谢谢

This should work: 这应该工作:

select distinct(session_id), max(time) - min(time) from test group by session_id

Then you have it grouped by session_id. 然后,将其按session_id分组。 To have it grouped by user: 要将其按用户分组:

select distinct(talentnum), max(time) - min(time) from test group by talentnum

First, get a list of visitors: 首先,获取访问者列表:

SELECT DISTINCT( sesssion_id ) as session FROM _yourTable_;

Then perform another query to get the start and end times of each visit: 然后执行另一个查询以获取每次访问的开始时间和结束时间:

SELECT MIN(time) as START_TIME, MAX_TIME(time) as END_TIME WHERE session_id = '$desired_session';

Then, retrieve the results via PHP and subtract the start time from the end time to get the total length of the visit. 然后,通过PHP检索结果,并从结束时间中减去开始时间,以获得访问的总长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM