Page 1 of 1

ranking players

Posted: Tue Aug 15, 2006 2:10 am
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

Posted: Tue Aug 15, 2006 2:30 am
by Oren
I don't get what you want to do. Can you explain it better?

Posted: Tue Aug 15, 2006 2:51 am
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);

Posted: Tue Aug 15, 2006 3:19 am
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

:?:

Posted: Tue Aug 15, 2006 3:32 am
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

Posted: Wed Aug 16, 2006 1:27 am
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.