LimitedStreak Posted June 30, 2012 Posted June 30, 2012 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 Quote
Seker Posted June 30, 2012 Posted June 30, 2012 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. Quote
KyleMassacre Posted June 30, 2012 Posted June 30, 2012 (edited) 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 June 30, 2012 by KyleMassacre Quote
LimitedStreak Posted July 1, 2012 Author Posted July 1, 2012 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 Quote
SilverStar Posted July 1, 2012 Posted July 1, 2012 Here you go: http://php.net/manual/en/language.operators.increment.php Quote
bineye Posted July 1, 2012 Posted July 1, 2012 mysql_query("select * from `users` and `status`='Alive' Does this actually show a working leaderboard? Quote
Seker Posted July 1, 2012 Posted July 1, 2012 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. Quote
Djkanna Posted July 1, 2012 Posted July 1, 2012 (edited) $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; Here you go: http://php.net/manual/en/language.operators.increment.php Edited July 1, 2012 by Djkanna Fixed my quoting SilverStar. Quote
LimitedStreak Posted July 2, 2012 Author Posted July 2, 2012 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 Quote
SilverStar Posted July 2, 2012 Posted July 2, 2012 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] Quote
LimitedStreak Posted July 2, 2012 Author Posted July 2, 2012 Not the fetch Rank but rankPos. So if you want to show the user what rank he is, how would i do that? Quote
SilverStar Posted July 2, 2012 Posted July 2, 2012 Not the fetch Rank but rankPos. So if you want to show the user what rank he is, how would i do that? You're already doing it. :confused: You're not being very clear hence the confusion. Quote
LimitedStreak Posted July 2, 2012 Author Posted July 2, 2012 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.