-5

How do i create a Table (HTML) with JSON data? This is my JSON data:

{
"7627":
  {"amt":2000,"pc":"3","bId":"1"},
"7868":
  {"amt":0,"pc":"2","bId":"1"},
"7990":
  {"amt":0,"pc":"2","bId":"1"},
}
phrogg
  • 888
  • 1
  • 13
  • 28

1 Answers1

0

First decode into an Array:

$yourArray = json_decode($yourJsonString, true)

then build the Table with

foreach (array_expression as $key => $value) {
   echo "<tr><td> ...

EDITED After update the question is duplicate

Here is Your json value i changed into array

$array = json_decode{'
"7627":
  {"amt":2000,"pc":"3","bId":"1"},
"7868":
  {"amt":0,"pc":"2","bId":"1"},
"7990":
  {"amt":0,"pc":"2","bId":"1"},
"8214":  
  {"amt":0,"pc":"3","bId":"1"},
"10331":
  {"amt":0,"pc":"2","bId":"1"}
}', true);

after that this is the table view use by foreach:

echo '<table border="1px">';
foreach ($array as $key => $single){
    echo '<tr>
            <td>
                '.$key.'
            </td>
            <td>
                '.$single['amt'].'
            </td>
            <td>
                '.$single['pc'].'
            </td>
            <td>
                '.$single['bId'].'
            </td>
        <tr>';  
}
echo '</table>';

I just echoed the values if you want to change you can use with concatenate operator for the table data(td)...

Nawin
  • 1,653
  • 2
  • 14
  • 23
Matthias Neubert
  • 275
  • 1
  • 5
  • 24