Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This JSON and curl commands are very new to me...currently what I have is the data in JSON form which is parsed through a URL shown just as one huge array the array is echoed for each instance. What I am trying to achieve is to put all of this data in a table via php. Below is the code I have...It displays nothing at the moment and am unsure where I am going wrong.

<div id="one">
<?php
$url = 'http://173.36.21.72:8777/v2/meters/disk.read.bytes';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Auth-Token: Example']);
$result = curl_exec($ch);
$data = json_decode($result,true);
curl_close($ch);
?>
</div>



<?php

echo '<table>';
echo '<tr><th>Username</th><th>Period</th><th>Room</th><th>Next?</th></tr>';

$n = 0;

foreach ($data as $key => $jsons) {
foreach ($jsons as $key => $value) {
    echo '<tr>';
echo '<td>'.$data[$n]['counter_name'].'</td>';
echo '<td>'.$data[$n]['user_id'].'</td>';
echo '<td>'.$data[$n]['resource_id'].'</td>';
echo '<td>'.$data[$n]['timestamp'].'</td>';
  echo '<td>'.$data[$n]['resource_metadata'].'</td>';

echo '</tr>';

$n++;
} 
}
echo '</table>';

?>

Thanks in advance..

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.