Rank function (Like MS Excel)

I am curious to know if there is a easy way to rank values using php. I have googled for a while and can’t seem to turn up any relevant results. I have a few dynamic values, that I need to rank by the highest value.
Example:

<table>
<tr>
<th>Total Call Attempts</th><th>Rank</th>
</tr>
<tr>
<td>5026200</td><td>Rank</td>
</tr>
<tr>
<td>5455370</td><td>Rank</td>
</tr>
<tr>
<td>2156424</td><td>Rank</td>
</tr>
</table>

Do any of you have any ideas? Any help is appreciated.
TIA

Define rank.

You could try using rsort() or some similar function if you have the information in an array…

By rank I would like to take a range of values from the db, and assign a rank.
For example
Let’s say i have a field called Total Call AttemptsI would like to rank by the amount of call attempts.

Total Call Attempts | Rank

1000 | 1
900 | 2
800 | 3

I hope this clarifies things. Thanks in advance.

Ahhh. Look at the SQL keywords ORDER BY. If you are using MySQL see
http://dev.mysql.com/doc/mysql/en/Sorting_rows.html

Order by would work if the “Rank” field existed in the database, however it does not. I would like to (hopefully) use a php function to define rank dynamically.
I hope this helps.

Guess you could use the max() mathmatical function.

I would put it all into an array and use one of the array sorting functions to sort it.

Manual -> Search -> functions ->type array (will give you all the array functions - right before user comments - so you can also see how to create one) Or http://www.php.net/manual/en/ref.array.php :)

Sponsor our Newsletter | Privacy Policy | Terms of Service