Display only a specific product with PHP

Asked

Viewed 77 times

-1

I’m making a sales website, on my product has a button called acquire that when clicked it leads to a checkout page, but on this checkout page was to display only the product on which it was clicked, but this displaying all products in the databases, follows below my code

but the main question is, how can I display only the chosen product?

<?php 

  if (isset($_GET['produtos']) && isset($_GET['id']) && !empty($_GET['produtos']) && !empty($_GET['id'])) {
    $id = DBEscape(strip_tags(trim($_GET['id'])));
    switch ($_GET['produtos']) {
      case 1:
        DBUpDate('produtos', array('status' => 1), "id = '{$id}'");
        break;
      case 2:
        DBUpDate('produtos', array('status' => 0), "id = '{$id}'");
        break;
      case 3:
        DBDelete('produtos', "id = '{$id}'");
        break;
    }

  }

$produtos = DBRead('produtos', 'ORDER BY data DESC');

    if (!$produtos)
      echo '<div class="col-md-10 text-center" style="padding-left: 20%;">
                <div class="alert alert-danger">
                        <strong>ERROR!</strong> Nenhum produto encontrado.
                </div>
          </div>';
    else 
            foreach ($produtos as $produtos):
?>
<section style="padding-top: 6%; padding-left:5%;" class="container">

  <div class="col-md-6">
    <div class="panel panel-c">
      <div class="panel-heading">
        <h3 class="text-center text">Informações</h3>
      </div>
      <div class="panel-body">
        <div>
          <center>
            <img src="<?php echo $produtos['img']; ?>">
          </center>

        </div>
        <br>
        <div>
          <h3 class="text-center text">Descrição</h3>
        </div>
        <br>
        <div>
          <?php echo $produtos['des']; ?>
        </div>
      </div>
    </div>
  </div>

  <div class="col-md-4">
    <div class="panel panel-c">
      <div class="panel-heading">
        <h3 class="text-center text">Checkout</h3>
      </div>
      <div class="panel-body">
        <div>
          <p style="float: left;">Produto:</p>
          <p style="float: right;">
            <?php echo $produtos['n_produto']; ?>
          </p>
          <br>
          <br>
          <p style="float: left;">Valor:</p>
          <p style="float: right;">R$
            <?php echo $produtos['valor']; ?>
          </p>
          <br>
          <br>
          <p style="float: left;">Cupom:</p>
          <p style="float: right;">Nenhum</p>
        </div>
        <br>
        <br>
        <br>
        <button class="btn btn-c">Finalizar Compra</button>
      </div>
    </div>
  </div>

</section>

<?php endforeach; ?>
  • 1

    In this case you would have to store the id of the products you selected in cookies or in session. To the next screen you filter only the products selected by the user...

2 answers

1

Add the clause WHERE here:

$produtos = DBRead('produtos', 'WHERE seu criterio de busca, ORDER BY data DESC');
  • Could you put in the code done? 'Cause I didn’t get it very well

-1

I believe that solves;

$produtos = DBRead('produtos', "WHERE id = '{$id}'");

Browser other questions tagged

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