Jump to content

Recommended Posts

I have here a simple table:

 

avatar_name                            dt_detection

 

Walegg Etzel                            2007-05-30 19:51:41

Plotunium Paine                          2007-05-30 19:55:03

Brain Cazalet                            2007-05-30  20:03:55

Sebby Voyager                          2007-05-31  08:05:31

Urban Loon                                2007-05-31  08:08:31

Klaas Berjis                                2007-06-01  08:09:05

 

 

Note: the date and time of detect is one field only.

 

Now based on the table above, I would like to create two queries such as below:

 

1. Current online:

Assuming the date right now is 2007-05-30, how do I create a query that display the number of avatar on a current date.

 

2. Total visits:

This is the cumulative count for the number of avatar visits. It should not only be unique Avatar visits. For example, if Walegg Etzel visited. She leaves and then back later on. That should log 2 counts for this statistic).

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/57042-create-a-query/
Share on other sites

So far this is what I have been doing, this is for current online.

 

This is script returns nothing.

 

$table = "tablename";
$today = gmdate("Y-m-d H:i:s");
$expire = gmdate("Y-m-d 23:59:59");


$result2 = mysql_query( "SELECT COUNT(*) FROM $table where avatar_group = 'Central' AND dt_detection BETWEEN $today AND $expire group by avatar_name");
$numofrows2 = mysql_num_rows($result2); 

 

where avatar_group is a name of the group and dt_detection is detection datetime type of file, it should count how many avatars on it.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/57042-create-a-query/#findComment-281822
Share on other sites

the query should be

SELECT SUM(COUNT(dt_detection)  as total_visits FROM $table where avatar_group = 'Central' AND dt_detection BETWEEN '$today' AND '$expire' group by avatar_name

which results the total no of visits in required period for particular group.

It could be better if you use date data type on the dt_detection column, if you use varchar or some other it increases the execution time.Might, there will be other way of writing this query very simple.

 

Link to comment
https://forums.phpfreaks.com/topic/57042-create-a-query/#findComment-281897
Share on other sites

But how you add to the query when a certain avatar log off then later on shall we say 5 minutes he/she log on again, then that should log 2 counts for this statistics.

as long as you are inserting user login time when he login again in  dt_detection column , it comes under the count.

 

Link to comment
https://forums.phpfreaks.com/topic/57042-create-a-query/#findComment-284713
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.