Possible? (player rank)

For general discussion of the Poker Mavens software
Post Reply
Alex
Posts: 53
Joined: Sun Mar 08, 2009 10:08 pm

Possible? (player rank)

Post by Alex »

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?
Kent Briggs
Site Admin
Posts: 5878
Joined: Wed Mar 19, 2008 8:47 pm

Re: Possible? (player rank)

Post by Kent Briggs »

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>
Post Reply