I'm totally not good with arrays and I have a database query that return this:
ID USER TASK Points Time
1 admin Accounting 1 -7
1 admin Accounting 1 -15
1 admin Accounting 1 -1146
1 admin Accounting 1 -2
1 admin Accounting 1 -3
2 Mike Encoding 1 -7
2 Mike Encoding 1 -55
2 Mike Encoding 1 0
2 Mike Encoding 1 -6
3 Adam Printing 1 -5
3 Adam Printing 1 -12
3 Adam Printing 1 -7
3 Adam Printing 1 -4
3 Adam Printing 1 -8
3 Adam Printing 1 -10
I've use a loop to count how many points each user have but I got a problem getting their average time which is (sum of time / count(time))
SO far my code is this:
while($row = mysqli_fetch_assoc($result))
{
$countCase[$row['TASK']] = isset($countCase[$row['TASK']]) ? $countCase[$row['TASK']] + 1 : 1;
$countUser[$row['TASK']][$row['USER']] = isset($countUser[$row['TASK']][$row['USER']]) ? $countUser[$row['TASK']][$row['USER']] + 1 : 1;
}
it basically count all the occurences but having difficulty getting the average time also is this array good for inserting it into a database or better suggestion?
SUM(),COUNT()andGROUP BY(SUM(Time)/COUNT(ID)) AS TimeAveragewithGROUP BY USERwill work. Or withGROUP BY USER, TASKorGROUP BY TASK, USER. Whichever suits your case.