0
I am layman in PHP and JSON, I have this code below that is working. It brings the values of a form
, but all in the same PHP tag, I would like to separate and put in an organized table, for example: Name, Price, Quantity, Subtotal.
Follow the code, I hope you understand, I thank you very much for the strength!
<?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>
Puts php inside the table tag after tr of the header generating another tr inside the loop and td for each information. Then for every loop he gives you a new line.
– Willian Coqueiro
I’ll test it here
– Hemerson Prestes
I put nothing else after the
– Hemerson Prestes
It was supposed to be table after that foreach($array_data as $obj){ more of the error
– Hemerson Prestes