OK - the table was generated with your code - my appreciation! no errors, or anything... but - there is the whole list of
raw JSON from the API that is displayed above the table... I wanted to see if this could be added/changed:
1. this JSON to not appear there but rather be used as the source for variables that we need to get;
2. the table to have those "Part Number", etc. areas to be generated from the JSON list, and not hardcoded....
(like appear inbetween EOR thingies to be inserted into the table, but not handcoded in like in the example that
works now, but from the JSON list)
Here is what I have now (minus the actual URL) and it works - a generated table below a bunch of raw JSON:
<?php
$url = 'http://api.domain.com/1.0/parts/parts?categoryGroupID=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Auth-Token: Example']);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = curl_exec($ch);
if (!$result) {
echo 'Curl error: ' . curl_error($ch);
die();
}
$result = <<<EOR
[
{"PartID":456,"Category":3,"Status":"another status","Timestamp":"99999"},
{"PartID":123,"Category":5,"PartNumber":1267,"Description":"blabla....","Status":"some status","Timestamp":"123456789","Datasheet":"some value"},
{"PartID":456,"Category":2,"Description":"some description","Timestamp":"99999"}
]
EOR;
$data = json_decode($result, true);
$header = array();
foreach ($data as $jsons)
$header = array_values(array_unique(array_merge($header,array_keys($jsons))));
echo '<table border="1">';
echo '<tr><th>'.implode('</th><th>',$header).'</th></tr>';
foreach ($data as $jsons) {
echo '<tr>';
$row = array();
foreach ($header as $h)
$row[$h] = (isset($jsons[$h])) ? $jsons[$h] : '';
echo '<td>'.implode('</td><td>',$row).'</td>';
echo '</tr>';
}
echo '</table>';
?>