This method is used to count the number of new users per day in a month.

Source: Internet
Author: User

This method is used to count the number of new users per day in a month.

Now there is a requirement: the Administrator selects a month and displays the number of new users per day for this month.

First, obtain the date selected by the Administrator, and then obtain the start Timestamp and end timestamp of the month. Then, compare it with the addtime field in the member table to obtain the list of new users in the month, this is not hard to achieve.

How can we get the number of new users per day? If you want to use statements such as select count (1) in combination with conditions such as addtime> = begin_time + 86400 and addtime <= begintime + 172800 to query, it would be too scary to avoid complicated operations first, in addition, you must query 30 or 31 times for one operation.

Now that we can get the new user list members in the current month, we can also know the addtime of each user. Now we can traverse the entire members list, use the date as the key name and the number of users as the key value to create a new array. If the addtime of a record already exists in the array, add 1, if it does not exist, create a new element with this addtime.

<? Php $ arr_mem = array (); foreach ($ members as $ k => $ v) {$ datetime = substr ($ v ['addtime ); // get the year, month, and day // obtain the number of new users per day if (array_key_exists ($ datetime, $ arr_mem) {$ arr_mem [$ datetime] + = 1 ;} else {$ arr_mem [$ datetime] = 1 ;}} var_dump ($ arr_mem); die;/* array (size = 31) '2017-12-01 '=> int 64 '2017-12-02' => int 2013 '2017-3 3 '=> int 2013 '2017-4 4' => int 191 '2017-12-05 '=> int 217' 2013-12-06 '=> int 228' 20 13-12-07 '=> int 148 '2017-12-08' => int 91 ...... */?>




How to count the number of new users for a community website every day?

Are you referring to the number of members that can be viewed on the Community website management page
If you are referring to the daily page views of a website, you can install a third-party statistics plug-in, such as 51la, quantum statistics, webmaster statistics, etc.

How can I query the number of new users?

If the logon time field is set to 'datetime' type and the table name is TABLENAME, the number of new users today is:
Select count (distinct id) as newcount
From tablename
Where convert (varchar (10), Logon Time, 120) = convert (varchar (10), getdate (), 120)
And id not in
(Select count (distinct id) as newcount
From tablename
Where convert (varchar (10), Logon Time, 120) <convert (varchar (10), getdate (), 120 ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.