Jump to content

php pulling only Json file info


Clinsta

Recommended Posts

So i currently have this code(Linked in Pastebin link) attempting to pull multiple arrays but having no luck and wondering if i could get a hand. The Json file example will be linked as well as the php.

 

PHP - http://pastebin.com/FRuGdXyi

JSON - http://pastebin.com/d1iVkiN3

 

The total_count can be different depending on the user as well as the array info.

Link to comment
https://forums.phpfreaks.com/topic/297578-php-pulling-only-json-file-info/
Share on other sites

That's how i was shown to pull info from json, it works with another api that i am using but the ['%'] was a placeholder because that number can vary depending on user. it follows the steps of the array. Here is an example of it working. http://pastebin.com/GQZ97AvB / http://pastebin.com/9bCEYmzE / http://gyazo.com/0542954b90d9a7d7858c4f0c00914ec5.png

$gameQuery['response'] ['total_count'] will only return the total count from here   "total_count": 4,   which is four

 

To get the games you want to use $gameQuery['response'] ['games'], Preferably use a foreach loop to iterate over each game. Example

$gameQuery = json_decode($gameInfo, true);

echo "Total Games: " . $gameQuery['response'] ['total_count'] . "<br />\nThese are:<br />\n";
foreach($gameQuery['response']['games'] as $gameInfo)
{
    // playtime_forever returns total time game has been played in minutes, 
    // divided by 3600 to convert to hours
    $hoursPlayed = ceil($gameInfo['playtime_forever'] / 3600);

    echo "<p><b>" . $gameInfo['name'] . "</b> - Hours played: $hoursPlayed</p>\n";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.