JamesC Posted October 26, 2013 Posted October 26, 2013 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. Quote
sniko Posted October 26, 2013 Posted October 26, 2013 $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 } :) Quote
JamesC Posted October 26, 2013 Author Posted October 26, 2013 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. Quote
sniko Posted October 26, 2013 Posted October 26, 2013 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. Quote
KyleMassacre Posted October 27, 2013 Posted October 27, 2013 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++; } 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.