Request for API help... if you've got the time

For discussion of the Poker Mavens server module and other administration topics

Request for API help... if you've got the time

Postby CCCP » Thu Jul 09, 2009 8:57 pm

Hi all,

I'm not familiar with API or PHP. I've tried reading it, and will continue to study it, but I was wondering if anyone here was willing to help out with some code in the meantime.

What I'm trying to do is add some code to one of my site's sidebars that displays the last 5 or so players to log in, and the time and date they logged in. A "nice to have" would also be if that particular player is currently at a table.

I assume the code would have to be similar to the Chips Leader example, whereby an array of LastLogin values is created, sorted and then displayed. Unfortunately due to my lack of knowledge of PHP that's about as far as I've got at the moment.

Anway, thanks in advance for anyone who can help. I'll try and further brush up my coding skills in the meantime =)
CCCP
 
Posts: 12
Joined: Mon Jun 15, 2009 8:27 pm

Re: Request for API help... if you've got the time

Postby CCCP » Thu Jul 09, 2009 11:25 pm

Acutally, i've had a stab at it and come up with the following modification to the Chip Leader example:

Code: Select all
<html>
<body>
<?php

  include "API.php";  // API $url and $pw values set here

  // Fetch the Site Name using the SystemGet API command.

  $params = "Password=" . $pw . "&Command=SystemGet&Property=SiteName";
  $api = Poker_API($url,$params);
  $result = $api["Result"];
  if ($result == "Error") die("Error: " . $api["Error"]);
  $sitename = $api["Value"];

  // Fetch the list of players using the AccountsList API command.

  $params = "Password=" . $pw . "&Command=AccountsList&Fields=Player,LastLogin";
  $api = Poker_API($url,$params);
  $result = $api["Result"];
  if ($result == "Error") die("Error: " . $api["Error"]);

  // Iterate through the players in the response and create a associative
  // chips array keyed on player name.

  $accounts = $api["Accounts"];
  $lastlogin = Array();
  for ($i = 1; $i <= $accounts; $i++)
  {
    $player = $api["Player" . $i];
    $lastlogin[$player] = $api["LastLogin" . $i];
  }

  // Sort array in decending order.

  arsort($lastlogin);

  // Display results in an html table.

  echo "<table border='1' cellpadding='5'>\r\n";
  echo "<tr><th colspan='2'>$sitename – Recent Logins</th></tr>\r\n";
  echo "<tr><th>Player</th><th>Last Login</th></tr>\r\n";
  foreach ($lastlogin as $p => $l)
  {
    echo "<tr><td>$p</td><td>$l</td></tr>\r\n";
  }
  echo "</table><br>\r\n";

?>
</body>
</html>



I haven't tried it yet, but I'm hoping it will work. One question I have is how the $p and $l ($c in the original Chip Leader example) work.
CCCP
 
Posts: 12
Joined: Mon Jun 15, 2009 8:27 pm

Re: Request for API help... if you've got the time

Postby Kent Briggs » Thu Jul 09, 2009 11:50 pm

CCCP wrote:One question I have is how the $p and $l ($c in the original Chip Leader example) work.


This PHP tutorial on using the foreach loop with an associative array explains it pretty well:

http://www.tizag.com/phpT/foreach.php
Kent Briggs - [email protected]
Briggs Softworks - http://www.briggsoft.com
Kent Briggs
Site Admin
 
Posts: 3865
Joined: Wed Mar 19, 2008 8:47 pm


Return to Site Administration

Who is online

Users browsing this forum: Google [Bot] and 11 guests