I am setting up Coin Warz API in my website, and API sending response in JSON Format and by JSON data response, i am trying to display it in table format using PHP, But Nothing happening.
JSON Response - Array ( [Success] => 1 [Message] => 996 api calls remaining.
[Data] => Array
(
[CoinName] => Bitcoin
[CoinTag] => BTC
[BlockCount] => 558860
[Difficulty] => 5883988430955.4
[BlockReward] => 12.5
[IsBlockExplorerOnline] => 1
[IsExchangeOnline] => 1
[Algorithm] => SHA-256
[ExchangeRates] => Array
(
[0] => Array
(
[Exchange] => Bitfinex
[ToUSD] => 3653.3
[ToBTC] => 1
[Volume] => 13083.6930094
[TimeStamp] => 1547674251.583
)
[1] => Array
(
[Exchange] => CEX.io
[ToUSD] => 3663.8
[ToBTC] => 1
[Volume] => 414.26963602
[TimeStamp] => 1547674248.653
)
[2] => Array
(
[Exchange] => itBit
[ToUSD] => 3589.99
[ToBTC] => 1
[Volume] => 2320.923
[TimeStamp] => 1547674245.113
)
[3] => Array
(
[Exchange] => hitbtc
[ToUSD] => 3579.68
[ToBTC] => 1
[Volume] => 22642.04
[TimeStamp] => 1547674242.827
)
[4] => Array
(
[Exchange] => Bitstamp
[ToUSD] => 3587.77
[ToBTC] => 1
[Volume] => 7681.97313751
[TimeStamp] => 1547674201.397
)
[5] => Array
(
[Exchange] => Coinbase
[ToUSD] => 3607.29
[ToBTC] => 1
[Volume] => 0
[TimeStamp] => 1547674201.117
)
)
[BlockTimeInSeconds] => 600
[HealthStatus] => Healthy
[Message] =>
)
)
PHP Code -
<?php`$json =file_get_contents("https://www.coinwarz.com/v1/api/coininformation/?
apikey=6b51849101ca4e4bb353d719546e919c&cointag=BTC");`$data = json_decode($json, true);` if (count($data->Data)) {
// Open the table
echo "<table>";`// Cycle through the loop
foreach ($data[0]->Data as $idx => $Data) {
// Output a row
echo "<tr>";
echo "<td>$Data->CoinName</td>";
echo "<td>$Data->CoinTag</td>";
echo "</tr>";
}`// Close the table
echo "</table>";
}
?>`
I expecting all value in table format like - [CoinName] [CoinTag] [BlockCount] [Difficulty] [BlockReward] and So on.
Try this hope it work, you decoded response in array not object.
$json = file_get_contents("https://www.coinwarz.com/v1/api/coininformation/?apikey=6b51849101ca4e4bb353d719546e919c&cointag=BTC");
$data = json_decode($json, true);
if (count($data['Data'])) {
// Open the table
echo '<table><tr>
<td>CoinName</td><td>CoinTag</td>BlockCount<td>Difficulty</td><td>BlockReward</td><td>Algorithm</td>
</tr>';
echo "<tr>";
foreach ($data as $key => $Dataarray) {
//echo '<pre>'; print_r($Dataarray);exit;
echo "<td>".$Dataarray['CoinName']."</td>";
echo "<td>".$Dataarray['CoinTag']."</td>";
echo "<td>".$Dataarray['BlockCount']."</td>";
echo "<td>".$Dataarray['Difficulty']."</td>";
echo "<td>".$Dataarray['BlockReward']."</td>";
echo "<td>".$Dataarray['Algorithm']."</td>";
}
echo "</tr></table>";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.