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
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 />";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

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.