Hi,
I have 3 structures, which I am trying to count the overall number of entries in, and then the number of entries with a specific key/value pair. Then I would like to work out a percentage using these numbers.
I am getting a Division by zero
error in the Kirby Debugger and can’t work out why at all.
This is the code on my page:
$section1 = $blockName . 'LeadershipAndCommunicationKeyTasks';
$section2 = $blockName . 'CurriculumKeyTasks';
$section3 = $blockName . 'TimetableAndPlanningKeyTasks';
$one = $kirby->user()->$section1()->yaml();
$two = $kirby->user()->$section2()->yaml();
$three = $kirby->user()->$section3()->yaml();
$allProgress = array_merge($one, $two, $three);
$complete = 0;
$pending = 0;
$incomplete = 0;
$overall = count($allProgress);
foreach ($allProgress as $oneProgress):
if ($oneProgress['progress'] == 'complete') {
$complete++;
}
elseif ($oneProgress['progress'] == 'pending') {
$pending++;
}
else {
$incomplete++;
}
endforeach;
$percentageComplete = ($complete / $overall) * 100;
echo $percentageComplete;
The error is on the line $percentageComplete = ($complete / $overall) * 100;
. If I echo $overall
I get 9 (which is correct), likewise $complete
is 2, which is right.
I have no idea what to try next. If I hard-code the 9 everything works fine. Can anyone shed any light?
Also if there is a better method for what I am doing when using Kirby I would be happy to learn