Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Trying to find a users rank

Codes here !

Moderators: macek, egami, gesf

Trying to find a users rank

Postby Jakbaehl » 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.
Anyone?
Code: Select all
$query = "SELECT * FROM lbzi4_jvarcade_leaderboard` ORDER BY points DESC";
$db->setQuery($query);
$rows = $db->loadObjectList();
$i = 0;
foreach ( $rows as $row ) {
while ($row->userid <>42){
$i++;
}
echo $i;
echo ": "  . $row->userid ."<br>";
}
Jakbaehl
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sat Apr 28, 2012 1:15 pm

Re: Trying to find a users rank

Postby QueenBea » Sun Apr 29, 2012 5:24 am

Hello

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
QueenBea
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Apr 18, 2012 1:50 am

Re: Trying to find a users rank

Postby Jakbaehl » 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.
Jakbaehl
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sat Apr 28, 2012 1:15 pm

Re: Trying to find a users rank

Postby Jakbaehl » 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 ...
Jakbaehl
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sat Apr 28, 2012 1:15 pm

Re: Trying to find a users rank

Postby minimihi » Sun Apr 29, 2012 9:23 am

If 'Player 1' has 358points and 'Player 2' has 360points, will both of them have rank 3?
User avatar
minimihi
New php-forum User
New php-forum User
 
Posts: 238
Joined: Sat Apr 14, 2012 11:57 am
Location: Vilnius, Lithuania


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron