我需要遍历这些数组,并将这些值放入它们各自的表中,表名应该是medal+key,即medal117
下面是脚本:
<?php
//incude sql database connection
include_once('sql.php');
//include api key
include_once('api.php');
$gameId = "448434948";
$gamertag = "Jam1efoster";
$GetGameDetails = "http://www.bungie.net/api/reach/reachapijson.svc/game/details/".$apiKey."/".$gameId;
$output = file_get_contents($GetGameDetails);
$obj = json_decode($output);
//echo $output."<br/>";
foreach($obj->GameDetails->Players as $players) {
if ($players->PlayerDetail->gamertag == $gamertag) {
foreach($players->SpecificMedalCounts as $SpecificMedalCounts) {
$medal = $SpecificMedalCounts;
echo '<pre>'.print_r($medal,1).'</pre>';
}
}
}
?>目前,它输出:
stdClass Object
(
[Key] => 117
[Value] => 1
)
stdClass Object
(
[Key] => 2
[Value] => 1
)
stdClass Object
(
[Key] => 85
[Value] => 8
)
stdClass Object
(
[Key] => 101
[Value] => 1
)发布于 2011-02-21 07:51:33
你想要比这更多的东西吗?假设您已经建立了与数据库的连接。
mysql_query(sprintf(
'INSERT INTO `medal%d` SET `value` = %d', $medal->Key, $medal->Value
));根据您对问题的评论,这更多的是关于访问类的属性。
来自文档,链接如下:
在类方法中,可以使用$
->属性形式访问属性、常量和方法
https://stackoverflow.com/questions/5060941
复制相似问题