The following code is not a simple way to achieve ah, I think this is too complicated to write, if you write one months of data, it is not necessary to write 30 case
I'm a novice, I beg the hero's help
Reply to discussion (solution)
I don't see what you want to do.
Can you explain what your needs are?
I don't see what you want to do.
Can you explain what your needs are?
I get all this week's data from the database, and then judge the number of times each day, such as today is Thursday, I get from the database from Monday to Thursday data, and then get the Monday how much data, Tuesday how much, Wednesday how much, Thursday how many, if today is Sunday, I got all the data this week, Then respectively get Monday Tuesday Wednesday Thursday etc is how much. Later to expand to the month, get the daily.
I mean, the procedure above means
First get all the data that is queried from the database. Then the initial daily number is 0, then if the judgment is placed in the loop data inside, respectively, determine the date of the day, and then the corresponding number of days +1, and finally all the data output can be.
Or do you have any other simple way to achieve it? Need to take into account the pressure of the database and program execution speed.
With recursion ...
If you get a week of data from a database,
Then, set $r [' Date '] to retrieve the time data, then there is
$c = Array (0,0,0,0,0,0,0);
In the Loop
$c [Date (' W ', $r [' Date '])]++;
$c is the number of daily counts
If you get the January data from the database,
Then, set $r [' Date '] to retrieve the time data, then there is
$c = Array_fill (1, 31, 0);
In the Loop
$c [Date (' d ', $r [' Date '])]++;
$c is the number of daily counts
don't see what you want to do
can you explain what your needs are?
I get all this week's data from the database, and then determine how many each day, such as today is Thursday, I get from the database from Monday to Thursday data, and then get the Monday how much data, Tuesday how much, Wednesday how much, Thursday how much, if today is Sunday, I got all the data this week, Then respectively get Monday Tuesday Wednesday Thursday etc is how much. Later to expand to the month, get the daily.
My program above means
to get all the data that was queried from the database first. Then the initial daily number is 0, then if the judgment is placed in the loop data inside, respectively, determine the date of the day, and then the corresponding number of days +1, and finally all the data output can be.
or do you have any other simple ways to implement it? Need to take into account the pressure of the database and program execution speed.
If you just increase the number of days it is, this is very simple
just save it with an array
if you are adding it by the day of the week, this is very simple:
directly with the array $days=array (0,0,0,0,0,0,0);//Based on date ( ' W ', $r [' Date '])-the number of days of the week, such as: "0" (Sunday) to "6" (Saturday) an array of
so that
you only need to
$days [Date (' W ', your date)]++; You've judged
if you're on a monthly basis, then you define an array of arrays labeled 1-31, the initial values are arrays of 0, and the others are the same as the weeks.
If you get a week of data from a database,
Then, set $r [' Date '] to retrieve the time data, then there is
$c = Array (0,0,0,0,0,0,0);
In the Loop
$c [Date (' W ', $r [' Date '])]++;
$c is the number of daily counts
If you get the January data from the database,
Then, set $r [' Date '] to retrieve the time data, then there is
$c = Array_fill (1, 31, 0);
In the Loop
$c [Date (' d ', $r [' Date '])]++;
$c is the number of daily counts
Thank you, already solved, 6 floor of Chinmo Moderator is this idea, really think alike, thank you!