0

I have an array like this:

Array
(
    [Team Name 1] => Array
        (
            [0] => Array
                (
                    [P] => 1
                    [CID] => 1
                    [S] => School 1
                )

            [1] => Array
                (
                    [P] => 1
                    [CID] => 1
                    [S] => School 1
                )

            [2] => Array
                (
                    [P] => 4
                    [CID] => 1
                    [S] => School 1
                )

            [3] => Array
                (
                    [P] => 5
                    [CID] => 1
                    [S] => School 1
                )

        )

    [Team Name 2] => Array
        (
            [0] => Array
                (
                    [P] => 1
                    [CID] => 5
                    [S] => School 2
                )

        )

    [Team Name 3] => Array
        (
            [0] => Array
                (
                    [P] => 3
                    [CID] => 3
                    [S] => School 2
                )

            [1] => Array
                (
                    [P] => 3
                    [CID] => 3
                    [S] => School 2
                )

            [2] => Array
                (
                    [P] => 6
                    [CID] => 13
                    [S] => School 2
                )

        )

    [Team Name 4] => Array
        (
            [0] => Array
                (
                    [P] => 4
                    [CID] => 1
                    [S] => School 3
                )

            [1] => Array
                (
                    [P] => 6
                    [CID] => 1
                    [S] => School 
                )

            [2] => Array
                (
                    [P] => 6
                    [CID] => 1
                    [S] => School 3
                )

        )

)

Is it possible to count the average of each School by counting two points from every team that has the same school? As you can see some Teams have more than two points. It should only calculate the two most recently added points per team. How would i achieve this?

At the moment my SQL/PHP query is like this:

$query1 = $db->prepare("SELECT points_1 As P, school As S, name As N, points.city_id As CID FROM points INNER JOIN teams ON teams.id = points.team_id INNER JOIN schools ON school.school_id = teams.school_id ORDER BY points.P ASC");

$query1->execute();
$Calc = $query1->fetchAll();

    $schoolAVG = array();
foreach ($Calc as $AVG) {
  $schoolAVG[$AVG['N']][] = array('P'=>$AVG['P'],'CID'=>$AVG['CID'],'S'=>$AVG['S']);
}
Pullapooh
  • 161
  • 1
  • 4
  • 14
  • Average of what do you want to count? Also it will be easier if data was formatted as table. – Bulat Aug 26 '14 at 15:13
  • @Bulat The average of total points(P) per school(S). But only the latest two points per team should be added to the average. – Pullapooh Aug 26 '14 at 15:18

0 Answers0