# Problem with Ranking code

**URL:** <https://forum.kirupa.com/t/problem-with-ranking-code/279876>\
**Category:** programming\
**Created:** [January 20, 2009, 8:37am UTC](https://forum.kirupa.com/t/problem-with-ranking-code/279876 "2009-01-20T08:37:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![selliott](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@selliott](https://forum.kirupa.com/u/selliott)\
**Post date:** [January 20, 2009, 8:37am UTC](https://forum.kirupa.com/t/problem-with-ranking-code/279876/1 "2009-01-20T08:37:15Z")

</div>

I need help fine tuning my code. This code shows ranking like:

Rank - Points  
1 - 120  
2 - 100  
2 - 100  
3 - 99

But I need it to show it like:

1 - 120  
2 - 100  
2 - 100  
**4** - 99

\*\*Notice the 4th result is ranked 4th instead of 3rd…since the two tied for 2nd are actually 2nd and 3rd.

```php

                <?php
    
    echo '<table cellpadding="3" cellspacing="0" style="width:100%;">
                    <tr>
                        <td>Rank</td><td>User</td><td>Points</td>
                    </tr>';
    $rank = 0;
                    
    while($row = mysql_fetch_array($Points)){ 
    
    $score = $row['Points'];
    
           $r = ($score == $oldScore)? $rank : ++$rank;
         echo '
         
         <tr>
         <td class="topline">' . $r . '</td>
         <td class="topline">' . $row['Name'] . '</td>
         <td class="topline">' . $score . '</td>
         </tr>';
    
    $oldScore = $score;
    }
    echo '</table>';
    
    ?>

```
