Is there an easy way to show, on the website, the users rank using php.
like you are 50/1000 players for example...
just curious because many users want to see where they stand against other users?
Possible? (player rank)
-
- Site Admin
- Posts: 5880
- Joined: Wed Mar 19, 2008 8:47 pm
Re: Possible? (player rank)
Try something like this. I just took the chip leaders code I made previously and only showed the selected player.
Code: Select all
<html>
<body>
<?php
if (isset($_REQUEST["Search"])) // page load via search button
{
include "API.php"; // API $url and $pw values set here
$player = $_REQUEST["Player"];
if ($player == "")
{
echo "No player name entered. Click the back button.";
exit;
}
// Fetch the list of players using the AccountsList API command.
$params = "Password=" . $pw . "&Command=AccountsList&Fields=Player,Balance";
$api = Poker_API($url,$params,true);
$result = $api["Result"];
if ($result == "Error") die("Error: " . $api["Error"]);
// Iterate through the players in the response and create an associative
// chips array keyed on player name.
$accounts = $api["Accounts"];
$chips = Array();
$found = false;
for ($i = 1; $i <= $accounts; $i++)
{
$p = $api["Player" . $i];
if (strcasecmp($player,$p)==0) $found = true;
$chips[$p] = $api["Balance" . $i];
}
if ($found == false)
{
echo "Player " . $player . " not found. Click the back button.";
exit;
}
// Sort array in decending order.
arsort($chips);
// loop through array looking for player
$rank = 0;
foreach ($chips as $p => $c)
{
$rank++;
if (strcasecmp($player,$p)==0)
{
echo $p . " rank is " . $rank . " of " . $accounts . " with " . $c . " chips";
break;
}
}
exit;
}
?>
<!-- display input form on first load -->
<!-- post results back to same page -->
<h3>Player Rank</h3>
<form method="post">
Screen name:<br/>
<input type="text" name="Player" />
<input type="submit" name="Search" value="Search" />
</form>
</body>
</html>