Can mysql-php update data for two consecutive weeks by day?

Source: Internet
Author: User
{Code ...} to get '{code ...} 'The purpose is to retrieve the number of registrars registered on the current day and the number of registrants pushed forward for 14 days on the current day. The current practice is to loop count '{code ...} 'The result is that a total of 28 count operations are performed, and the efficiency is quite low.
use_id reg_time1      2015-12-01 2      2015-12-02 3      2015-12-02 4      2015-12-03 5      2015-12-03 6      2015-12-03 7      2015-11-30   

To get
`

Reg_time count (2 weeks) 0 02015-11-29 0 02015-11-30 1 12015-11-31 0 12015-12-01 1 22015-12-02 2 42015-12-03 3 7

`

The purpose is to retrieve the number of registrants registered on the current day and the number of registrants registered on the previous 14 days.

The current practice is to loop count
`

$lasttime=strtotime(date("Y-m-d",time()))-14*3600*24;$firsttime=strtotime(date("Y-m-d",time()))+3600*24;$result = array()for($i=13;$i>=0;$i--){    $first=date("Y-m-d",$firsttime-$i*3600*24);    $last=date("Y-m-d",$lasttime-$i*3600*24);    $today=date("Y-m-d",time()-$i*24*3600);    $tmp1 = "select count(1) from table where reg_time > $last and reg_time < $last";    $tmp2 = "select count(1) from table where reg_time = $today "    $result[][date] =$today;    $result[][count1] =$tmp1;    $result[][count2] =$tmp2;        }

`

The result is that a total of 28 count operations are performed, and the efficiency is quite low.

Reply content:
use_id reg_time1      2015-12-01 2      2015-12-02 3      2015-12-02 4      2015-12-03 5      2015-12-03 6      2015-12-03 7      2015-11-30   

To get
`

Reg_time count (2 weeks) 0 02015-11-29 0 02015-11-30 1 12015-11-31 0 12015-12-01 1 22015-12-02 2 42015-12-03 3 7

`

The purpose is to retrieve the number of registrants registered on the current day and the number of registrants registered on the previous 14 days.

The current practice is to loop count
`

$lasttime=strtotime(date("Y-m-d",time()))-14*3600*24;$firsttime=strtotime(date("Y-m-d",time()))+3600*24;$result = array()for($i=13;$i>=0;$i--){    $first=date("Y-m-d",$firsttime-$i*3600*24);    $last=date("Y-m-d",$lasttime-$i*3600*24);    $today=date("Y-m-d",time()-$i*24*3600);    $tmp1 = "select count(1) from table where reg_time > $last and reg_time < $last";    $tmp2 = "select count(1) from table where reg_time = $today "    $result[][date] =$today;    $result[][count1] =$tmp1;    $result[][count2] =$tmp2;        }

`

The result is that a total of 28 count operations are performed, and the efficiency is quite low.

select reg_time,count(1) from table where reg_time > $last and reg_time < $last group by reg_time

Query by SQL grouping

To address your problem, we recommend that you directly obtain daily update data and add it in PHP. In this way, only one SQL statement is available.

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.