PHP daily, weekly, and monthly click ranking statistics

Source: Internet
Author: User

Copy codeThe Code is as follows:
$ Now = time (); // current time
$ StrUpdate = "Update $ tbl_article set hits = hits + 1 ";
If (date ("d", $ lasthittime) = date ("d", $ now) {// same day
$ StrUpdate = $ StrUpdate. ", dayhits = dayhits + 1 ";
} Else {
$ StrUpdate = $ StrUpdate. ", dayhits = 0 ";
}
If (date ("W", $ lasthittime) = date ("W", $ now) {// same week
$ StrUpdate = $ StrUpdate. ", weekhits = weekhits + 1 ";
} Else {
$ StrUpdate = $ StrUpdate. ", weekhits = 0 ";
}
If (date ("m", $ lasthittime) = date ("m", $ now) {// same as January
$ StrUpdate = $ StrUpdate. ", monthhits = monthhits + 1 ";
} Else {
$ StrUpdate = $ StrUpdate. ", monthhits = 0 ";
}
$ StrUpdate = $ StrUpdate. ", lasthittime = '$ now' where id = '$ id'"; // update the click Time
$ Fsql-> query ($ StrUpdate );

I don't know how easy it is. Let's analyze it first.
However, it seems that there are some problems. If it is a day, you should first judge that the year and month are the same, and then judge the day.

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.