My url does not receive the id parameter in the display? id=. Why?

Asked

Viewed 32 times

0

Question: My url does not receive the parameter id in the mostra?id=.

Code:

<table class="table table-striped table-bordered table-hover">
<?php foreach($produtos as $p): ?>
  <tr>
    <td><?= $p->nome ?></td>
    <td><?= $p->valor ?></td>
    <td><?= $p->descricao ?></td>
    <td><?= $p->quantidade ?></td>
    <td><a href="https://localhost/estoque/public/produtos/mostra?id=<?php 
        $p->id ?>"><span class="glyphicon glyphicon-search"></span></a></td>
  </tr>
<?php endforeach ?>

  • 1

    Try to change <?php $p->id ?> for <?= $p->id ?>

  • Our solved the problem, thanks anyway!

1 answer

1


In the part where you define the link:

<a href="https://localhost/estoque/public/produtos/mostra?id=<?php 
        $p->id ?>"><span class="glyphicon glyphicon-search"></span></a>

You are not "writing" the value of id. So in order for the value to appear you have to make a echo:

<?php echo $p->id; ?>

Or you can use the abbreviated form:

<?= $p->id ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.