Jump to content

PHP Points Ranking Help


lJesterl

Recommended Posts

Hey guys if someone would aim me LJesterL I could explain a little better. Basicly i'm writing a ladder system and i'm done with everything except adjusting the ranks when a loss is reported. I thought I could do it but I cant figure it out. Here's basicly how I need it to work. I need to select id from ladder_$li[ladderid] ORDER by points then I need to update the ranks and set ranks 1 through whatever based on who has the highest points to who has the lowest and if they have 0 points do not update the rank. Can someone help me do this?

Link to comment
https://forums.phpfreaks.com/topic/93465-php-points-ranking-help/
Share on other sites

well to list all the ranks you could go..

 

<?php
$rank = 0;
$query = mysql_query("SELECT * FROM ladder WHERE points > 0 ORDER BY points") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
  $user = $row['user'];
  $points = $row['points'];
  $rank++;
  echo "$user is ranked $rank with $points points<br />";
}
?>

 

That would list all users as

USER is ranked 1 with 10 points

USER2 is ranked 2 with 7 points

etc etc

 

now to update them would be easy..

 

<?php
$rank = 0;
$query = mysql_query("SELECT * FROM ladder WHERE points > 0 ORDER BY points") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
  $ladderid = $row['ladderid'];
  $user = $row['user'];
  $points = $row['points'];
  $oldrank = $row['rank'];
  $rank++;
  $update = mysql_query("UPDATE ladder SET rank='$rank' WHERE ladderid='$ladderid'") or die(mysql_error());
  echo "$user is now ranked $rank with $points points. Their old rank was $oldrank<br />";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.