I am a layman in PHP and JSON, I have this code below that is working. It brings the values of a form
, however everything in the same PHP tag, would like to separate and put in an organized table, for example: Name, Price, Quantity, Subtotal.
Follow the code, I hope you understand, thank you very much for the force!
<?php
if(!isset($_POST["json_dados"])) die("Post não enviado.");
$array_dados = json_decode($_POST["json_dados"]);
$total = 0;
foreach($array_dados as $obj)
{
echo 'Nome: '. $obj->nome . '<br>';
echo 'Preço: '. $obj->preco . '<br>';
echo 'Quantidade: '. $obj->qtd . '<br>';
echo 'Subtotal: '. $obj->subtotal . '<br>';
echo '<br><br>';
$total = $total + $obj->subtotal;
}
echo 'Total: '.$total;
?>
<table width="95%" border="1" align="center">
<tr>
<td width="26%"><div align="center">Nome</div></td>
<td width="41%"><div align="center">Preco</div></td>
<td width="33%"><div align="center">Quantidade</div></td>
<td width="33%"><div align="center">Subtotal</div></td>
</tr>
</table>