Well, I'm working with Bungie's Halo Reach API. Right now my code will get all the game ids for a particular player.
I want to store the game ids in a mysql database and then in the future if a player wants to update the database the script will only get the game ids that aren't already in the database.
The script gets the most recent page $iPage = '0';
Then if HasMorePages
is equal to true it gets the next page $iPage++
until HasMorePages
is false.
Each page gives 25 game ids the last page may have less.
So basically I want to get game ids that weren't there when the script was first run, without making unnecessary calls to the API. How could I do that?
<?php
include_once('sql.php'); // MySQL Connection
include_once('api.php'); // API unique identifer string
$gamertag = 'jam1efoster'; // Gamertag
$variant = 'Unknown'; // Unknown gets all game variants
$iPage = '0'; // 0 is the most recent page
while(!$endPages == true){
$GetGameHistory = "http://www.bungie.net/api/reach/reachapijson.svc/player/gamehistory/".$apiKey."/".rawurlencode(strtolower($gamertag))."/".$variant."/".$iPage;
$output = file_get_contents($GetGameHistory);
$obj = json_decode($output);
//echo $output;
$mPages = $obj->HasMorePages;
if($mPages == false){$endPages = true;}
foreach($obj->RecentGames as $recentgames) {
$gameId = $recentgames->GameId;
//echo $gameId.'<br />';
}
//echo $iPage.'<br />';
$iPage++;
}
?>