How to deal with the implementation of query consecutive days

Source: Internet
Author: User
The number of consecutive days of query implementation I want to implement this function from the current time, the reverse query of consecutive days of time, if one in the middle is not continuous with the previous time, no information can be found! If you can directly implement mysql statements, it would be better if you cannot use php + mysql. please give tips to Xiaomei here. I just learned php and mysql, so I am a Cainiao .... thank you .... ------ solution ------------------ this can be achieved in the number of consecutive days of data design query
I want to implement this function
From the current time, the reverse query is performed for consecutive days. if one of them is not consecutive with the previous time, no information can be found!
If mysql statements can be directly implemented better, it is also good if php + mysql cannot be used.
Please give tips to Xiaomei here. I just learned php and mysql, so I am a Cainiao... thank you ....

------ Solution --------------------
This can be implemented during data design.
Two fields are used for the last logon time. The current consecutive logon days are used (the default value is 0)

When a user logs on, the current date and the last logon time are determined.

Case 0: if the previous day is connected to the current consecutive logon days ++
Case 1: the day. Today. No updates required
Case 2: After several days. Reset to 0
Case 3: If the current time is smaller than the last logon time. What you can do
------ Solution --------------------
It can be implemented in the MYSQL stored procedure.

However, it is recommended that the PHP code be clear.
------ Solution --------------------
The first floor is suitable for you.
------ Solution --------------------
Php program directly determines the conditions!
------ Solution --------------------
Create a logins field and a lastdate field in the user table.
Log on to the user and read lastdate to determine whether the last day was yesterday? For $ logins = $ logins + 1, update lastdate to the current logon time. If the last logon time is not today or yesterday $ logins = 1, the number of consecutive logins is 1.

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.