I am having trouble getting this loop to do what I would like it to. I need to display information from a multidimensional array in order. The order has already
been sorted in the array using a usort. How do I display this information the correct way?
The array takes the format:
$teams['teamid]['wins...losses...ties...name'] = "value";
ex:
$teams['t23']['name'] = "Yankees";
$teams['t23']['wins'] = "30";
$teams['t23']['losses'] = "10";
$teams['t23']['ties'] = "0";
$teams['t24']['name'] = "Reds";
$teams['t24']['wins'] = "40";
etc...
<?php
function display_standings($division)
{
$teams = get_wlt($division);
$maxwins = $teams[0]['wins'];
?>
<table class="tables">
<tr class="column_names">
<td class="first"> </td>
<td>Team</td>
<td>Wins</td>
<td>Loss</td>
<td>Tie</td>
<td>PCT</td>
<td>Games Back</td>
<td>Runs Allowed</td>
<td>Runs Scored</td>
<td class="last">Run Ratio</td>
</tr>
<?php $position = 0;
foreach ($teams as $key)
{
foreach ($key as $row)
{ ?>
<tr>
<td class="first"><?php $position = $position + 1; echo $position."."; ?></td>
<td><?php echo ucwords($row['name']); ?></td>
<td><?php echo $row['wins']; ?></td>
<td><?php echo $row['losses']; ?></td>
<td><?php echo $row['ties']; ?></td>
<td><?php $wins = $row['wins'] + .5*$row['ties']; $losses = $row['losses'] + .5*$row['ties']; $tot= $wins + $losses; if ($tot != 0){$pct = $wins / $tot; printf("%0.3f", $pct); }?></td>
<td><?php $gb = $maxwins - (.5*$row['ties']) - $row['wins']; if ($gb <= "0"){$gb = "-"; }echo $gb; ?></td>
<td><?php $runs_allowed = get_runs_allowed(addslashes($row['name']), $division); echo $runs_allowed; ?></td>
<td><?php $runs_scored = get_runs_scored(addslashes($row['name']), $division); echo $runs_scored; ?></td>
<td class="last"><?php if($runs_scored != "0" || $runs_allowed != "0"){$run_ratio = $runs_scored / $runs_allowed; printf("%0.3f", $run_ratio);}else{printf("%0.3f", 0);} ?>
</tr>
<?php
}
}
?>
</table><?php
} ?>
Please help. I can't get this to work properly. I want the foreach to act like the mysql_fetch_assoc and just pull the values from name, wins, losses, ties for each team and add to line a calculation for win PCT, games back, runs allowed, runs scored, and a run ratio.
Thanks so much everyone for your help and support. I greatly appreciate it.