MasterACE14 Posted October 25, 2007 Share Posted October 25, 2007 Evening, I asked a question a couple of days ago, about how I would rank players, I know how to UPDATE each players rank in the database, and I know how to echo each player with their ranks, but still don't know how to assign each player their own unique rank. here is my previous post with all the details: http://www.phpfreaks.com/forums/index.php/topic,164867.0.html Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/74707-ranking-players-revisited/ Share on other sites More sharing options...
adam291086 Posted October 25, 2007 Share Posted October 25, 2007 i am a little confused. You have generated a rank by add three values together. Are you struggling with how to order them compared to this rank you have generated. for example rank 150 = 1 rank 149 = 2 rank 147 = 3 Quote Link to comment https://forums.phpfreaks.com/topic/74707-ranking-players-revisited/#findComment-377673 Share on other sites More sharing options...
Wuhtzu Posted October 25, 2007 Share Posted October 25, 2007 No, his problem is that two or more players could easily have the same rank which he would like to avoid. But MasterACE14, as suggested in the other thread, you simply need to settle with the fact that two players can have the same score and then their individual rank is determined by alphabetic sorting or something like that. Quote Link to comment https://forums.phpfreaks.com/topic/74707-ranking-players-revisited/#findComment-377682 Share on other sites More sharing options...
MasterACE14 Posted October 26, 2007 Author Share Posted October 26, 2007 yes, I know all this, but I'm stuck with the coding for "Assigning each players Actual Rank", 1, 2, 3 etc etc. How do I give them the ranks in the first place? example: <?php while ($row = mysql_fetch_assoc( $result ) ) { // assign each players rank, how do I do that?? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74707-ranking-players-revisited/#findComment-378401 Share on other sites More sharing options...
LemonInflux Posted October 26, 2007 Share Posted October 26, 2007 <?php /* SORRY IN ADVANCE FOR THE MASS MISTAKES */ /*** Make a rank table, with (basic) this: - 1st column: Rank. The user's rank - 2nd column: User. Finds the user - 3rd column: Score. Then, the coding... ***/ // First, we get the user's score from wherever you're keeping it... $usersql = mysql_query("SELECT * FROM `users` WHERE `user` = *username*"); // <-- change username to a var or whatever. $user_row = mysql_fetch_row($usersql); // Then, query the db. Here we're finding everyone with a lower score $sql = mysql_query("SELECT * FROM `ranks` WHERE `score` < '". $user_Row[2] ."'") or die(mysql_error()); // And add 1 to all of their ranks while($player_row = mysql_fetch_assoc($sql)){ $another_var = mysql_query("UPDATE `ranks` SET `rank` = '". $player_row['rank'] + 1 ."' WHERE `ranks`.`rank` > ". $user_row) or die(mysql_error()); /*** OK, so now we've found the user's rank, and updated the table (adding 1 to every person with a lower rank, now we need to find our player and update his rank ***/ $last_sql = mysql_query("UPDATE `ranks` SET `rank` = '". $user_row['rank'] + 1 ."' WHERE `ranks`.`rank` > ". $user_row) or die(mysql_error()); // <-- Once again, change. /*** We've found all scores lower than our players, added 1 to their rank, and stuck our player in the gap. Sadly, I can't think of a way to do this without user/system prompts. Do a cron job or something. Sorry if this makes no sense what ever, it's too early in the morning. Tried to comment it a bit though just in case it's completely messed up. ***/ ?> Quote Link to comment https://forums.phpfreaks.com/topic/74707-ranking-players-revisited/#findComment-378414 Share on other sites More sharing options...
MasterACE14 Posted October 26, 2007 Author Share Posted October 26, 2007 I think thats exactly what I'm looking for , and it does make sense , I'll be putting it into my cronjob in a few hours. Thanks lemon Quote Link to comment https://forums.phpfreaks.com/topic/74707-ranking-players-revisited/#findComment-378465 Share on other sites More sharing options...
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.