开发者

Looping through pages from API

I'm trying to get all the gameids for a particular player. The API I am working w开发者_Python百科ith only returns 24 games per page. I just cant figure out how to loop though the pages.

When a player no longer has anymore pages $mPages will be equal to false.

The problem is adding 1 to $iPages so it can get the next page..

My current script:

<?php
//incude sql database connection
include_once('sql.php');
//include api key 
include_once('api.php');
//gamertag
$gamertag = "jam1efoster";
//variant- Valid values are "Campaign", "Firefight", "Competitive", "Arena", "Invasion", "Custom", "Unknown". "Unknown" returns all games.
$variant = "Unknown";
//page number 0 = most recent
$iPage = 0;

while(!$endPages == "stop"){

$iPage = $iPage++;

$GetGameHistory = "http://www.bungie.net/api/reach/reachapijson.svc/player/gamehistory/".$apiKey."/".rawurlencode($gamertag)."/".$variant."/".$iPage;

$output = file_get_contents($GetGameHistory);
$obj = json_decode($output);
echo $output;

$mPages = $obj->HasMorePages;
if($mPages == false){$endPages = "stop";}

foreach($obj->RecentGames as $recentgames) {
        $gameid = $recentgames->GameId;
        echo $gameid."<br/>";
    }

}
?>


Perhaps a while loop?

while (!endOfPages) {    
    getMoreGames();  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜