0
I’m starting now with the most complex queries within PHP. As always I played Wow I decided to learn a little about API with PHP using the Blizzard API that gives me some information.
After a lot of research I was able to pull the information inside a table, but I had a question: using the search of the pets as an example, and if I wanted my list to bring me only the pets with the level higher than 10 (pets collected->Stats->level)
Below is the code of how it is returning a table with all the pets and some information
the full json url is: https://us.api.battle.net/wow/character/Goldrinn/Lokinhaa?fields=pets&locale=pt_BR&apikey=3ps9yqk69mhjhy435m8sq4razamkwy25
<?php
$type = 'character';
$reino = 'Goldrinn';
$char = 'Lokinhaa';
$language = 'pt_BR';
$fields = 'pets';
$api_key = '3ps9yqk69mhjhy435m8sq4razamkwy25';
$url = "https://us.api.battle.net/wow/$type/$reino/$char?fields=$fields&locale=$language&apikey=$api_key"; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data, true); // decode the JSON feed
$pets = $characters['pets']['collected'];
?>
<table>
<tbody>
<tr>
<th>Pet</th>
<th>Spell</th>
<th>Level</th>
<th>Health</th>
<th>Power</th>
<th>Speed</th>
</tr>
<?php foreach ($pets as $pet) : ?>
<tr>
<td> <?php echo $pet['name']; ?> </td>
<td> <?php echo $pet['spellId']; ?> </td>
<td> <?php echo $pet['stats']['level']; ?> </td>
<td> <?php echo $pet['stats']['health']; ?> </td>
<td> <?php echo $pet['stats']['power']; ?> </td>
<td> <?php echo $pet['stats']['speed']; ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
?>
Possible duplicate of How to read and interpret a JSON file with PHP?
– Luís Almeida