循环浏览页面

时间:2011-02-20 16:13:04

标签: php

我正在尝试为特定玩家获取所有游戏玩法。我正在使用的API每页只返回24个游戏。我只是想弄清楚如何循环页面。

问题是为$ iPages添加1,以便它可以进入下一页..

我目前的剧本:

<?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/>";
    }

}
?>

1 个答案:

答案 0 :(得分:1)

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

$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/>";
    }
$iPage++;  // increment here
}

$ iPage = $ iPage ++;不会改变价值。它总是零。

相关问题