I am trying to calculate a ranking of a team in an ordered MySQL result set, and the issue I\'m having is detecting ties for the first team to show up with the tied
I like Ignacio's link to his answer. But if you still wanted to use PHP, you could collect the ranks by SCORE and assign teams to each score. It's probably not the most efficient way to do it, but it would work.
$ranks = array();
while ($row = mysql_fetch_assoc($result)) {
$ranks[$row['pts']][] = $row['team_id'];
}
$ranks would be an array that could look like...
$ranks[89] = array(1);
$ranks[87] = array(2);
$ranks[76] = array(3,4);
$ranks[52] = array(5);
Use a foreach on $ranks, and double check which way the points would come up (ascending or descending). You can use count() to see if there's a tie.