Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何更新游戏历史数据库?Bungie Halo Reach API_Php_Mysql_Api_Xbox360 - Fatal编程技术网

Php 如何更新游戏历史数据库?Bungie Halo Reach API

Php 如何更新游戏历史数据库?Bungie Halo Reach API,php,mysql,api,xbox360,Php,Mysql,Api,Xbox360,我在用Bungie的Halo Reach API。现在,我的代码将获得特定玩家的所有游戏ID 我想将游戏ID存储在mysql数据库中,然后在将来,如果玩家想要更新数据库,脚本将只获取数据库中不存在的游戏ID 脚本获取最新的页面$iPage='0' 然后,如果HasMorePages等于true,它将获得下一页$iPage++,直到HasMorePages为false。 每页提供25个游戏ID,最后一页可能更少 因此,基本上我希望获得脚本第一次运行时不存在的游戏ID,而不需要对API进行不必要的调

我在用Bungie的Halo Reach API。现在,我的代码将获得特定玩家的所有游戏ID

我想将游戏ID存储在mysql数据库中,然后在将来,如果玩家想要更新数据库,脚本将只获取数据库中不存在的游戏ID

脚本获取最新的页面
$iPage='0'
然后,如果
HasMorePages
等于true,它将获得下一页
$iPage++
,直到
HasMorePages
为false。 每页提供25个游戏ID,最后一页可能更少

因此,基本上我希望获得脚本第一次运行时不存在的游戏ID,而不需要对API进行不必要的调用。我该怎么做?

<?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++;
}

?>

考虑到我理解你的意图和要求。请尝试以下代码:

<?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
// get current ids
$result=mysql_query('SELECT ALL CURRENT IDS');// PUT YOUR SQL HERE !
$oldIds=array();
$newIds=array();
while($row=mysql_fetch_array($result))$oldIds[]=$row['id'];// might be different in your scenario
// get all ids, unfortunately
for(;;){
    $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);
    // get fresh ids
    foreach($obj->RecentGames as $recentgames) {
        if(in_array($recentgames->GameId, $oldIds))continue;// we already have this id
        $newIds[]=$recentgames->GameId;
    }

    if(!$obj->HasMorePages)break;// no more pages? break!
    $iPage++;
}

var_dump($newIds);
?>

我不熟悉bungie将游戏推向api的方法。如果订购了,请发表评论。我会修改我的代码。如果他们武断,那就有点倒霉了