Jump to content

Adding Count into array


stb74

Recommended Posts

Not sure whether the subject is correct but hopefully I can explain it ok.

 

I have a football/soccer League table that after I generate I run a foreach to display the league table, within this I add a position counter.

 

I end up with something like this

 

Position Team P W D L F A Pts

1          Malachians 11 6 3 2 24 16 21

2          Killyleagh YC 7 5 1 1 16 9 16

3          Newington YC 7 4 3 0 21 12 15

4          Comber Rec 9 4 3 2 20 22 15

5          Wellington Rec 8 3 3 2 17 16 12

 

I am now looking to add another position column but show the previous weeks position.

 

This is my code to generate the table data

 

foreach ($query->result() as $team) {

$_wins 			= $this->getWins($team->ID_TEAM,$ID_DIVISION,$ID_SEASON);
$_draws 		= $this->getDraws($team->ID_TEAM,$ID_DIVISION,$ID_SEASON);
$_previous_wins	= $this->getPreviousWins($team->ID_TEAM,$ID_DIVISION,$ID_SEASON);
$_previous_draws = $this->getPreviousDraws($team->ID_TEAM,$ID_DIVISION,$ID_SEASON);
$_loses 		= $this->getLoses($team->ID_TEAM,$ID_DIVISION,$ID_SEASON);
$_goalsfor 		= $this->getGoalsFor($team->ID_TEAM,$ID_DIVISION,$ID_SEASON);
$_goalsagainst 	= $this->getGoalsAgainst($team->ID_TEAM,$ID_DIVISION,$ID_SEASON);
$_goaldiff 		= ($_goalsfor - $_goalsagainst );

$_played		=	($_wins + $_draws + $_loses);
$_deductions 	= $this->getDeductions($team->ID_TEAM,$ID_DIVISION,$ID_SEASON);
$_tpoints		= $_deductions + (($_wins*$_points_for_win) + ($_draws*$_points_for_draw));
$_previous_points = $_deductions + (($_previous_wins*$_points_for_win) + ($_previous_draws*$_points_for_draw));

$_data[$team->ID_TEAM] = array("ID_TEAM"=> $team->ID_TEAM,
"team_name"=>	$team->team_name,
"Played"=>		$_played,
"Wins"=>		$_wins,
"Draws"=>		$_draws,
"Loses"=>		$_loses,
"GoalsFor"=>	$_goalsfor,
"GoalsAgainst"=>$_goalsagainst,
"GoalDiff"=>	$_goaldiff,
"Points"=>		$_tpoints,
"PPoints"=>		$_previous_points,
"Deductions"=>	$_deductions
);

}
$_data = sortOldTable($_data);

 

Link to comment
Share on other sites

Not sure whether this will help any but I thought that after I generate the table data I sort the league table on $PPoints ( Previous weeks points)

 

I maybe run the data through a foreach and add in a Position number for each team.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.