Trying to find a users rank

Codes here !

Moderators: egami, macek, gesf

Post Reply

Sun Apr 29, 2012 5:06 am

Hi all. I have a table with users, and their scores.
Now, i want to find a specific users rank, but i am stuck. This is within joomla.

This is the code i have that is the closest, buuuut, it don't work :(
The point here is that i want to know the rank of user 42 specificly.

Code: Select all

$query = "SELECT * FROM lbzi4_jvarcade_leaderboard` ORDER BY points DESC";
$rows = $db->loadObjectList();
$i = 0;
foreach ( $rows as $row ) {
while ($row->userid <>42){
echo $i;
echo ": "  . $row->userid ."<br>";

New php-forum User
New php-forum User
Posts: 6
Joined: Wed Apr 18, 2012 1:50 am

Sun Apr 29, 2012 5:24 am


You need to change your SQL statement

SELECT * FROM name of table in database
WHERE user = 42

user - is this the name of the column?

hope this helps


Sun Apr 29, 2012 6:05 am

Maybe i am not understanding what you are telling me, but i dont think so.
Lets say there are 4 players in the table. I want to know the rank of a spesific player.

For instance

Player 1 - 500 points.
Player 2 - 125 points.
Player 3 - 752 points.
Player 4 - 321 Points.

I want to output the rank of for instance Player 4. It would be (in this case) rank 3.
Hope i am making any sence here.


Sun Apr 29, 2012 6:16 am

Let me add that the rank it self is not a part of the table. It must be som sort of a count ordered by the points descending from what i can gather ...

User avatar
New php-forum User
New php-forum User
Posts: 236
Joined: Sat Apr 14, 2012 11:57 am
Location: Vilnius, Lithuania

Sun Apr 29, 2012 9:23 am

If 'Player 1' has 358points and 'Player 2' has 360points, will both of them have rank 3?

Post Reply