Help - Search - Members - Calendar
Full Version: PHP Group Array "teams" and add up points
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
godsdead
hey all smile.gif
Now i have been trying to figure this our for ages, and its just not coming to me :/

Heres the senario, im creating a flatfile points system for a school.
all information is read from an excel file, points are generated from an algorithm i created and the points per student are outputted, there is an output generaeted below:
i cant figure out how to just display the team and the teams overall points.
QUOTE
Name ID Attendance Milestone Actual Assessment R1 R2 R3 Team Points
Student1 1 90 4a 4a 1 0 0 Blue Team 16
Student2 2 75 5b 5c 2 1 1 Red Team 14
Student3 3 95 5c 3b 0 0 0 Blue Team 15
Student4 4 100 5a 6b 1 2 1 Blue Team 40
Student5 5 100 4b 4c 0 0 1 Green Team 30
Student6 6 65 6c 6a 0 1 0 Red Team 17
Student7 7 96 4a 5a 1 0 1 Green Team 26
Student8 8 98 3b 3a 1 2 2 Green Team 45


So i want to output something simple like this:
QUOTE
Green Team Overall Points: 150
Red Team Overall Points: 127
Blue Team Overall Points: 89


the furthest i got, was giving each student an array with points and team name..
CODE
// This skips the headings
     $i = 2;
// Create an array
     $studentinfo = array();
     while ($i <= $rowsc)
     {
// Student
         $no = $i++;
// Students ID
         $id = $data->val($no,2);
// The Team they belong too
         $team = $data->val($no,9);
// There overall points, which is grabbed from elsewhere
         $r3 = "$overalladded";
// Creating the array..
         $studentinfo[$id] = array("$team","$r3");
     }
// I tryed something with this, but didnt get very far
     //$unique_teams_array = array_unique($studentinfo);
     //ksort($studentinfo);
     // Output
     echo"<pre>";
         print_r($studentinfo);
     echo"</pre>";


which outputted:
CODE
Array
(
     [1] => Array
         (
             [0] => Blue Team
             [1] => 0
         )

     [2] => Array
         (
             [0] => Red Team
             [1] => 1
         )

     [3] => Array
         (
             [0] => Blue Team
             [1] => 0
         )

     [4] => Array
         (
             [0] => Blue Team
             [1] => 1
         )

     [5] => Array
         (
             [0] => Green Team
             [1] => 1
         )

     [6] => Array
         (
             [0] => Red Team
             [1] => 0
         )

     [7] => Array
         (
             [0] => Green Team
             [1] => 1
         )

     [8] => Array
         (
             [0] => Green Team
             [1] => 2
         )
)


sidenotes:
im using http://code.google.com/p/php-excel-reader/ to read the excel file.
rc69
CODE
     $studentinfo = array("Blue Team" => 0, "Red Team" => 0, "Green Team" => 0);
     for($i=2; $i <= $rowsc; $i++)
     {
         $studentinfo[$data->val($i,9)] += $data->val($i,10);
     }

Note: i'm assuming "$data->val($i,10)" is the points column.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.