syntax error, unexpected 'endforeach' (T_ENDFOREACH), expecting end of file. Does anybody have any idea why they made a mistake? [closed]

-2
<html>
<body>
<h1>Listagem de Produtos</h1>
   <table>
        <?php foreach($produtos as $p) ?>
     <tr>
        <td><?php $p->nome ?></td>
        <td><?php $p->valor ?></td>
        <td><?php $p->descricao ?></td>
        <td><?php $p->valor ?></td>
     </tr>
        <?php endforeach ?>
    </table>
</body>
</html>
    
asked by anonymous 09.08.2018 / 03:43

1 answer

3
<html>
<body>
<h1>Listagem de Produtos</h1>
   <table>
        <?php foreach($produtos as $p): ?>
     <tr>
        <td><?=$p->nome;?></td>
        <td><?=$p->valor;?></td>
        <td><?=$p->descricao;?></td>
        <td><?=$p->valor;?></td>
     </tr>
        <?php endforeach; ?>
    </table>
</body>
</html>

Try the above code. The code was missing : at $p) . I simplified his $p->valor .

To display a result of a variable on the screen you should use PHP echo or print .

The simplification made in your code was the printing of the value in the column of table <?=$variavel;?> displays the value of the direct variable on the screen.

More information about foreach in the PHP documentation

    
11.08.2018 / 01:02