Jump to content


PHP Group Array "teams" and add up points


1 reply to this topic

#1 godsdead

    Young Padawan

  • Members
  • Pip
  • 21 posts

Posted 14 July 2009 - 07:20 AM

hey all :)
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..
// 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:
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.c...p-excel-reader/ to read the excel file.

Edited by rc69, 14 July 2009 - 05:48 PM.


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 14 July 2009 - 05:51 PM

	 $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.

Edited by rc69, 14 July 2009 - 05:51 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users