Jump to content
MakeWebGames

Select highest users


JamesC

Recommended Posts

Want to run a daily cron that gives the top 5 users with the highest "battlepoints" rewards. But having some trouble figuring out how i would select the users, i can get a list of the top 5 players but i'm not sure how i would get each of their i'd's individually to send the rewards. Don't know if i should be using the MAX() funtion.

Help would be awesome.

Link to comment
Share on other sites

Use an identifier.

$query = "SELECT `userid`,`username` FROM `users` ORDER BY `battlepoints` DESC LIMIT 5";
$n = 1;
while($r = $db->fetch_row( $db->query($query) ) ) {
     //Do logic here.
    //$r['userid'] for their userid
    //$r['username'] for their username
    $n++;
}

 

Use the value of $n for their position. Simple.

Link to comment
Share on other sites

Using sniko's method still, and since you only want 5 you can do this

 

$query = "SELECT `userid`,`username` FROM `users` ORDER BY `battlepoints` DESC LIMIT 5";
$n = 1;
while($r = $db->fetch_row( $db->query($query) ) ) {
     //Do logic here.
    //$r['userid'] for their userid
    //$r['username'] for their username
   if ($n == 1)
       //do this
   //and just continue until you reach 5
    $n++;
}
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...