Looping imagestrings
Posted: Wed Oct 18, 2006 2:59 pm
I have a script that will get player stats and display them. It works fine but the results are unorganized. So I display the player stats in descending order by creating an array:
The output of this:
What I would like to do is to create a loop that outputs imagestring since I am making a png image.
Something similar to this:
But the loop has to be sorted by the players_kd and must also contaion the players name, player deaths and player kills. Can anyone give me any insight?
Code: Select all
$Player1_kills = get_data ($fr, "Player1_kills = ");
$Player1_deaths = get_data ($fr, "Player1_deaths = ");
$Player1_KD =($Player1_kills / $Player1_deaths);
$Player1_KD = round($Player1_KD, 3);
$Player2_kills = get_data ($fr, "Player2_kills = ");
$Player2_deaths = get_data ($fr, "Player2_deaths = ");
$Player2_KD =($Player2_kills / $Player2_deaths);
$Player2_KD = round($Player2_KD, 3);
$Player3_kills = get_data ($fr, "Player3_kills = ");
$Player3_deaths = get_data ($fr, "Player3_deaths = ");
$Player3_KD =($Player3_kills / $Player3_deaths);
$Player3_KD = round($Player3_KD, 3);
$score = array(
"Player1" => "$player1_KD",
"Player2" => "$player2_KD",
"Player3" => "$player3_KD",
);
// Sort the array in reverse order with its elements
arsort($score);
// Print 3 top elements.
for ($i=0; $i<3; $i++) { if (
$row = each($score)) { echo
"$row[key] $row[value]"
; }
}Code: Select all
Player3 1.786 Player1 1.327 Player2 0.88Something similar to this:
Code: Select all
header("Content-type: image/png");
$bg = "statsig1.png";
$im = @ImageCreateFromPNG($bg);
$width =1;
$font = 2;
$fonta = 3;
$white = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);
imagestring($im, $font, 24, 303, "Player1", $white);
imagestring($im, $font, 149, 303, $Player1_kills, $white);
imagestring($im, $font, 251, 303, $Player1_deaths, $white);
imagestring($im, $font, 350, 303, $Player1_KD, $red);
imagestring($im, $font, 24, 320, "Player2", $white);
imagestring($im, $font, 149, 320, $Player2_kills, $white);
imagestring($im, $font, 251, 320, $Player2_deaths, $white);
imagestring($im, $font, 350, 320, $Player2_KD, $red);
imagestring($im, $font, 24, 337, "Player3", $white);
imagestring($im, $font, 149, 337, $Player3_kills, $white);
imagestring($im, $font, 251, 337, $Player3_deaths, $white);
imagestring($im, $font, 350, 337, $Player3_KD, $red);