I have a table called “member_points”, which is set up like this:
|----|-------|----------|------------------------|
| id | uid | points | last_loggedin |
|----|-------|----------|------------------------|
| 1 | 1 | 5075 | 2012-08-02 02:04:00 |
|----|-------|----------|------------------------|
| 2 | 2 | 2026 | 2012-08-04 02:15:02 |
|----|-------|----------|------------------------|
I have a function below. I want the function to echo or return the rank like “Ranked #1” or “Ranked #2”, based on the number in the row “points”.
function getTopRanks($id) {
$sql = "SELECT MAX(points) AS toppoints FROM member_points";
$r = mysql_query($sql);
if ( $r !== false && mysql_num_rows($r) > 0 ) {
while ( $a = mysql_fetch_assoc($r) ) {
$points = stripslashes($a['toppoints']);
return ''.$points.'';
}
}
}
Can someone help me make this possible?
I think you are going to ranking user on the basis of points.
For such type of problem, i suggest you to first rank user on DESC order. Then pickup desire value form row.
this will solve your problem.:)
UPDATE AS YOUR REQUIREMENTS:
there should be return userPos+count. because count is increases up number of rows in table and the string ranked position is always remains same.
this will give result. Your can change return string according to your requirements. 🙂
thanks.