PHP script builder help

Hi i need a small php script making for me

What i need is to get the results of a group of members with the same title?

so for example
Player 1 [Title Red] with 2000 chips
Player 2 [Title Red] with 2000 chips
Player 3 [Title Blue] with 1500 chips
Player 4 [Title Blue] with 1500 chips

Add player 1 + 2 = 4000 chips
Add Player 3 + 4 = 3000 chips

So we get the results
Place Title Chips
01 Title Red 4000 chips
02 Title Blue 3000 chips

Multiple Players and Titles tho not just 2

Im not a php programmer but i had a go and got it to nearly work
email me at [email protected]

something like this:

<?php
// Player 1 Info
$title['red'][0]['name'] = "Player 1";
$title['red'][0]['chips'] = 2000;
// Player 2 Info
$title['red'][1]['name'] = "Player 2";
$title['red'][1]['chips'] = 2000;
// Player 3 Info
$title['blue'][0]['name'] = "Player 3";
$title['blue'][0]['chips'] = 1500;
// Player 4 Info
$title['blue'][1]['name'] = "Player 4";
$title['blue'][1]['chips'] = 1500;

$red_ttl = 0;
$blue_ttl = 0;

foreach ($title['red'] as $red) {
  $red_ttl = $red_ttl + $red['chips'];
}

foreach ($title['blue'] as $blue) {
  $blue_ttl = $blue_ttl + $blue['chips'];
}

$output = "<table><tr><td>Place</td><td>Title</td><td>Chips</td></tr><tr><td>01</td><td>";

if ($red_ttl > $blue_ttl) {
  $output .= "Title Red</td><td>" . $red_ttl . "</td></tr><tr><td>02</td><td>Title Blue</td><td>" . $blue_ttl;
} else {
  $output .= "Title Blue</td><td>" . $blue_ttl . "</td></tr><tr><td>02</td><td>Title Red</td><td>" . $red_ttl;
}

$output .= "</td></tr></table>";

echo $output;
?>

the above will do just what you’ve specified, but it’s not remotely elegant. using it for a large number of teams and players would involve hard-coding lots of arrays.

how are you planning to store the player/team data? knowing where the data are coming from would make it possible to tighten this up quite a bit and automate the array building at the top, the ranking, the output building, etc.

Sponsor our Newsletter | Privacy Policy | Terms of Service