How to get mysql data for a shopping cart

Asked

Viewed 44 times

0

Well, I’d like to know if there’s a better way: he looks for everything that has skin_type==2, and I wanted to make several types to sell, I would have a way to pick up item by item and put in a div or just like picking up everything ?

 <?php
                $consulta = $pdo->prepare("SELECT * FROM homesite");
                $consulta -> execute();

                $linhas = $consulta -> rowCount();

                foreach($consulta as $mostra):
            ?>
    <div class="card">
        <?php
if ($mostra['skin_tipo'] == 2) {?>
      <img class="skin"src="images/<?= $mostra['skin_img']?>" alt="Nome da Empresa: 
      <?= $mostra['skin_nome']?>" title="Nome da Empresa: <?= $mostra['skin_nome']?>">
      <div class="info">
      <h1 class="color-white text-center font-text-light-med font-weight-heavy bgcolor-black"><?= $mostra['skin_nome']?></h1> 
      </div>
      <p class="preccor">Por: R$ <?= number_format($mostra['skin_preco'], 2,',','.')?></p>
      <button class="bgcolor-red text-center btn"><a href="comprar.php?prod=<?= $mostra['id_skin']?>">Comprar</a></button>
        <?php } ?>
    </div>
    <?php endforeach; ?>
  • You want to show only what is skin_type=2?

  • That I have done, I wanted to pick up item by item, that I have the skin_type == 2, so that I did it all, because I wanted to make a caroulse with each item that has type = = 2

  • I’m trying to pick up by the id, but it still picks up all the field record, and I wanted to pick up only 1 at a time..

  • @Leocaracciolo I was wanting to pull separately each ( product that is registered in the database), and at the time my code searches all products registered in mysql and not 1 by 1 ex: if I go there by id, will appear 5 even if I have set to only id = 1.

  • I wanted to pick separately item by item, to make a Carousel

  • i used an if ($shows['id_skin'] =1)

  • but even with this if appears everything you have in the table.

  • @Leocaracciolo in this case the best to use is this from homesite Where id=1? but then I would have to do this for all ex items if I want to get 5, would that be 5 from homesite Where, is there any cleaner way to do that? I wanted to create kind of a slide with products .

  • @Leocaracciolo and would have made a Carousel pulling between the 5 and 10? Because the Carousel would need items separately no?

  • @Leocaracciolo is exactly this Carousel that is in the news section. http://www.neshastore.com/

  • your problem is riding the carousel right? enters the chat

Show 7 more comments

1 answer

1


  1. Bring in the query only those who have skin_tipo=2

    $consulta = $pdo->prepare("SELECT * FROM homesite WHERE skin_tipo=2");
    
  2. Change those lines

      $linhas = $consulta -> rowCount();
      foreach($consulta as $mostra):
    

    for these

      $fetchAll = $consulta->fetchAll(); 
      foreach($consulta as $mostra):
    

Code

$consulta = $pdo->prepare("SELECT * FROM homesite WHERE skin_tipo=2"); 
$consulta -> execute(); 

$fetchAll = $consulta->fetchAll(); 

foreach($consulta as $mostra): 

  // o que quer seja apresentado

endforeach; 
  • when you have a while we chat continue that subject ?

Browser other questions tagged

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