So right now I'm pulling data from a json API (battle.net) with this request
https://us.api.battle.net/wow/realm/status?locale=en_US&realms=runetotem&apikey=xxxxxxxxxxxxxxx
API key hidden intentionally, this returns the following
{
"realms": [{
"type": "pve",
"population": "medium",
"queue": false,
"wintergrasp": {
"area": 1,
"controlling-faction": 1,
"status": 0,
"next": 1433468324674
},
"tol-barad": {
"area": 21,
"controlling-faction": 1,
"status": 2,
"next": 1433465638814
},
"status": true,
"name": "Runetotem",
"slug": "runetotem",
"battlegroup": "Vengeance",
"locale": "en_US",
"timezone": "America/Los_Angeles",
"connected_realms": ["uther", "runetotem"]
}]
}
Which I am putting into an array using php and then attempting to call upon values from said array in an if statement, however the if statement is always firing true for my check. I don't understand why at all, if someone could please help that'd be great. Code below.
<?php
$json_url = "https://us.api.battle.net/wow/realm/status?locale=en_US&realms=runetotem&apikey=xxxxxxxxxxx";
$json = file_get_contents($json_url);
$data = json_decode($json, TRUE);
?>
<tr class="latestthreads_portal">
<td width="230px" class="trow3">
<strong>Realm Status</strong>
<span class="smalltext"><br />
<?php if ($data['realms'][0]['status'] == 2)
{
echo "up";
}
else{
echo "Down?";
}
?>
<br />
<br /> <div class="border"></div>
</span>
</td>
</tr>
Please excuse crappy formatting, in a rush.
You have comparison issues and data nesting issues, I think. It looks to me like you are comparing if (2 == true)
which evaluates to true
in php. http://php.net/manual/en/types.comparisons.php
Also you are only checking the status of the "realms" array, not the status of "tol-barad" and "wintergrasp" objects, not sure what you wanted, exactly.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments