Jump to content
MakeWebGames

Ranking help


LimitedStreak

Recommended Posts

Hey there people, just need some help please with php.

<code> <?php

$tsel = mysql_query("select * from `users` and `status`='Alive' order by `rankpoints` desc limit 1,10");

while ($top = mysql_fetch_array($tsel)) {

print "<tr>

<td align=left>  $tsel2<a href='ajax_user_info.php?viewuser=$top[username]' class='user_link' title='Click to view user info!' target='mainFrame'>$top[username]</a></td><td align=left>".makecomma($top[rankpoints])." XP</td></tr>";}

?>

</code>

Is there a way that i can rank the results so the person with the most rankpoints will be#1 and the least will be #10 so there will be a list with #1-#10 the users usernames and how much rankpoints they have?

I just don't know how to actually rank the results

Thank You so much in advance

Link to comment
Share on other sites

Hey there people, just need some help please with php.

<code> <?php

$tsel = mysql_query("select * from `users` and `status`='Alive' order by `rankpoints` desc limit 1,10");

while ($top = mysql_fetch_array($tsel)) {

print "<tr>

<td align=left>* $tsel2<a href='ajax_user_info.php?viewuser=$top[username]' class='user_link' title='Click to view user info!' target='mainFrame'>$top[username]</a></td><td align=left>".makecomma($top[rankpoints])." XP</td></tr>";}

?>

</code>

Is there a way that i can rank the results so the person with the most rankpoints will be#1 and the least will be #10 so there will be a list with #1-#10 the users usernames and how much rankpoints they have?

I just don't know how to actually rank the results

Thank You so much in advance

The ORDER BY statement should look something like this:

$tsel = mysql_query("SELECT * FROM users WHERE status='alive' ORDER BY rankpoints ASC,userid DESC LIMIT 10");[php]

I believe something like that should work.

And then, I think your table is right, but you just need to add a <td>$top['rankpoints']</td> in there. I think.

Link to comment
Share on other sites

Try:

 

$tsel = mysql_query("SELECT * FROM `users` WHERE `status`='Alive' ORDER BY `rankpoints` ASC LIMIT 1,10");
while ($top = mysql_fetch_array($tsel))

*disclaimer:

Im not too sure what its for so I hope it helps.

Also im not sure on what you need ALL the columns from the users table so its always good to call out exactly what you need for example:

$tsel = mysql_query("select username, userid, status, blah, blah, etc, etc from `users` WHERE `status`='Alive' order by `rankpoints` ASC LIMIT 1,10");
Edited by KyleMassacre
Link to comment
Share on other sites

Thanks for the replies:) btw the $tsel2 shouldnt be there

I am not sure if you understand what i meant. This piece of code show a perfect leaderbord

For example:

LimitedStreak 100 Rank Points

Seker 78 Rank Points

KyleMassacre 50 Rank Points

.. this goes on to show another 7 users in order from highest to lowest. I want to have ranks on the side so it will be like this:

#1 LimitedStreak 100 Rank Points

#2 Seker 78 Rank Points

#3 KyleMassacre 50 Rank Points

 

A number shows the users position on this leaderboard with #1 having the highest Rank Points and #10 having the lowest.

 

I just cant seem todo this so please try to help...Thank You:D

Link to comment
Share on other sites

mysql_query("select * from `users` and `status`='Alive' 

 

Does this actually show a working leaderboard?

I could be mistaken, but for listing the top three, you could maybe do something like this:

$tsele = mysql_query("SELECT COUNT(rankpoints) AS cnt FROM users WHERE status='Alive'");
$tsel = mysql_fetch_array($tsele);

echo "{$tsel['1']}";
echo "{$tsel['2']}"; etc, etc.

 

I could be way off track here, but it's a thought.

Link to comment
Share on other sites

$select = mysql_query ( ... );
if (mysql_num_rows($select) > 0) {

   $rankPos = 1; //Set as one (your first rank)
   while ($listing = mysql_fetch_array($select)) {

       echo 'Rank: #'.$rankPos.' ...';
       //$rankPos = 1, $rankPos = 2, with each loop through, $rankPos increases by one.
       $rankPos++; //Increment by 1.
   }
}

As mentioned;

Edited by Djkanna
Fixed my quoting SilverStar.
Link to comment
Share on other sites

That worked perfectly thank you very very much!

Thank you for all the replies, really helpful forum! ♥

BTW does anyone know how to the specific rank?

Just say i want do get one users rank?

For example:

#1 LimitedStreak 100 Rank Points

#2 Seker 78 Rank Points

#3 KyleMassacre 50 Rank Points

If i want to find Sekers position? Which would be #2, how would I do this? Thanks

Link to comment
Share on other sites

That worked perfectly thank you very very much!

Thank you for all the replies, really helpful forum! ♥

BTW does anyone know how to the specific rank?

Just say i want do get one users rank?

For example:

#1 LimitedStreak 100 Rank Points

#2 Seker 78 Rank Points

#3 KyleMassacre 50 Rank Points

If i want to find Sekers position? Which would be #2, how would I do this? Thanks

Display the rank where you display the other information?

$top[rank]
Link to comment
Share on other sites

Sorry for the unclear replies lol

The first post was asking for the leaderboard help which is now solved thank you but now if i want to get the rankPosition of a specific user, how would i do that?

Like saying to the user 'You are ranked at #48'. Hope this is more clear... Thanks :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...