Jump to content
MakeWebGames

Recommended Posts

Posted

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.

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

 

:)

Posted

Cheers, but say i wanted to give different rewards to each of the top 5 users

For example how exactly would i give the user with the 2nd highest battlepoints "20 gold"

I don't understand how you can differentiate the 5 users.

Posted

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.

Posted

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++;
}

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