php - Grouping data to get reports by intervals -
i posted question time ago on representing data per date horizontally on datatable. see here: datatables dates @ top , data cells going left right
with of thread able data display how wanted it. dates showing @ top, service provided on left , data associated date between 2 date paramters inside main body. (if there no data in particular date < td > display 0. see here: http://www.phpwin.org/s/ewbas6
after manipulating code further made dates of search dynamic proving form start date , end date, , dropdown options of:
- daily
- weekly
- monthly
- quaterly
- yearly
this allows interval of dates @ top become dynamic. of course doing changing value of 2nd parameter inside date while loop.
while (strtotime($date) <= strtotime($end_date)) { echo '<th>' . $date . '</th>'; $date = date('y-m-d', strtotime($date . ' +1day')); }
with parameter set @ weekly, value of +1day becomes +1week, @ monthly; value becomes +1month , on.
my issue:
when interval set daily, dates corresponding attendance counts displayed correctly once try increase interval +1week , above data not round week shown. check this:
[link1]per day: http://www.phpwin.org/s/ewbas6
[link2]per month: http://www.phpwin.org/s/xro3i6
looking @ array (modified on link2)
$result[] = array('service name' => 'health', 'date' => '2017-04-04', 'attendance' => 5); $result[] = array('service name' => 'payroll', 'date' => '2017-04-16', 'attendance' => 5); $result[] = array('service name' => 'saturday youth meeting', 'date' => '2017-04-03', 'attendance' => 1); $result[] = array('service name' => 'saturday youth meeting', 'date' => '2017-05-03', 'attendance' => 3); $result[] = array('service name' => 'payroll', 'date' => '2017-05-03', 'attendance' => 2); $result[] = array('service name' => 'payroll', 'date' => '2017-04-11', 'attendance' => 3); $result[] = array('service name' => 'payroll', 'date' => '2018-04-03', 'attendance' => 10);
you can see in array there multiple attendance entries in april, totaling 14 attendances in month during link2 interval increased month instead of showing 14 april (which sum of dates in particular month) shows value 1.
my live version takes array database used year(), month(), week() , day() function on date , used group by. query executes how want having issues working on php end.
Comments
Post a Comment