Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Non-unique ranking of rows

Status
Not open for further replies.

mellenburg

Programmer
Aug 27, 2001
77
US
I have a MYSQL table with the following type of values for variable x.

1
1
2
3
3
4

I want to rank these cells with the following values.

1, 1
1, 1
2, 3
3, 4
3, 4
4, 6

So if the values are equal, the ranking is the same. Using PHP, is there a way to retain the last value of the fetch_array so that I may compare it to the next value to determine whether or not to incriment rank, or to keep rank equal to the previous value.

Or, is there an easier technique to do this that I'm not aware of?
 
Something like this:
[tt]$prev = array('score' => 0);
$rank = 0;
while ($row = mysql_fetch_assoc($result))
{
if ($prev['score'] != $row['score'])
$rank++;
echo $row['score'] . &quot;, &quot; . $rank . &quot;<br />&quot;;
$prev = $row;
}[/tt]
should do the trick. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top