2011-04-13 4 views
0

Bungie의 Halo Reach API를 사용하고 있습니다. 지금 내 코드는 특정 플레이어에 대한 모든 게임 ID를 가져옵니다.게임 기록 데이터베이스를 업데이트하는 방법은 무엇입니까? Bungie Halo Reach API

게임 ID를 mysql 데이터베이스에 저장하고 싶습니다. 나중에 플레이어가 데이터베이스를 업데이트하고 싶다면 스크립트는 데이터베이스에 아직없는 게임 ID 만 가져옵니다. HasMorePages 그것이 HasMorePages이 거짓이 될 때까지 다음 페이지 $iPage++를 얻을 사실에 동일한 경우는

그런 다음 스크립트는 가장 최근의 페이지 $iPage = '0'; 을 가져옵니다. 각 페이지에는 마지막 페이지의 게임 ID가 25 개 있습니다.

그래서 기본적으로 스크립트를 처음 실행할 때 없었던 게임 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++; 
} 

?> 

답변

2

은 고려 난 당신이 뭘 하려는지 당신이 요구하는지 이해. 이 코드를보십시오 :

<?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); 
?> 

내가 방법 번지는 API에 게임을 밀어 수 있습니다 익숙 해요. 주문을 받으면 의견을 말하십시오. 그리고 코드를 수정합니다. 그들이 임의적이라면, 힘든 행운입니다.

관련 문제