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"},
}
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"},
}
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)...