Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/74707-ranking-players-revisited/
Share on other sites

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.

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

}
?>

<?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. ***/

?>

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.