Maybe something like this.
PHP Code:
$query = mysql_query("....");
while ($results = mysql_fetch_array($query)) {
// Sort each row into the id.
$array[$results[id]]['rows'][] = $results;
// Other things not specific per row.
$array[$results[id]['blah'] = $result['blah']
}
// Go through each team.
foreach ($array as $id => $team) {
// Go through each row.
foreach ($team['rows'] as $row) {
// Do stuff here, like calculations and stuff.
}
// Finish doing team related things.
eval('$fantasy_cricket_teamplayerbit .= "' . fetch_template('fantasy_cricket_teamplayerbit') . '";');
}
<3 foreach.