ranking players

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

ranking players

Post by jeeep »

I have made a php code that will take the value of a persons socre on a text file (where we manually enter the values such as 3 or 10), and use it as a players score. My question is, if possible, how would I rank someone according to there score?

Example:
PlayerA score: 5
PlayerB score: 7
PlayerC score: 0

with ranking php script ->
PlayerB score: 7
PlayerA score: 5
PlayerC score: 0


Here are some notes:
For the php code the players score looks like this

Code: Select all

$file=("scorecard.txt");
$fileget=file_get_contents($file);
$PlayerAwins = get_data ($fileget, "PlayerAwins = ");
$PlayerBwins = get_data ($fileget, "PlayerBwins = ");
$PlayerCwins = get_data ($fileget, "PlayerCwins = ");
and then this is displayed as text on to an image

Code: Select all

imagettftext ($im, 11, 0, 100, 212, $black, $font, $PlayerAwins);
imagettftext ($im, 11, 0, 200, 212, $black, $font, $PlayerBwins);
imagettftext ($im, 11, 0, 300, 212, $black, $font, $PlayerCwins);

Thanks
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

I don't get what you want to do. Can you explain it better?
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

I want to rank the player with the most wins at the top and the player with the least wins at the bottom. But I am also using this code to display the players wins:

Code: Select all

imagettftext ($im, 11, 0, 100, 212, $black, $font, $PlayerAwins);
imagettftext ($im, 11, 0, 200, 212, $black, $font, $PlayerBwins);
imagettftext ($im, 11, 0, 300, 212, $black, $font, $PlayerCwins);
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

So what you want to do is taking this:

PlayerA score: 5
PlayerB score: 7
PlayerC score: 0

and sort it like this:

PlayerB score: 7
PlayerA score: 5
PlayerC score: 0

:?:
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

$array = array(1 => 1, 2 => 3, 3 => 2);

arsort($array);

print_r($array);

/**
* array (
*      2 => 3,
*      3 => 2,
*      1 => 1,
*      );
**/
or

Code: Select all

SELECT `players`, `scores` FROM `playerScores` WHERE `blah` = `blah` ORDER BY `scores` DESC
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Jenk wrote:

Code: Select all

$array = array(1 => 1, 2 => 3, 3 => 2);

arsort($array);

print_r($array);

/**
* array (
*      2 => 3,
*      3 => 2,
*      1 => 1,
*      );
**/
or

Code: Select all

SELECT `players`, `scores` FROM `playerScores` WHERE `blah` = `blah` ORDER BY `scores` DESC
Well this script isnt using SQL (but judging by the looks of it, wish it were). I am sort of confussed as to how I would get $PlayerAwins, $PlayerBwins, and $PlayerCwins into an array similar to this and then display it in an imagettftext maner.
Post Reply