0

I made this code to show the results, but it only works on the first card, the other results get the same layout unless the picture, and the cards are in a vertical line, one on top of the other.

<div class="container my-3">

    <div class="row">

    <div class='col-12 col-md-6 col-lg-3 mb-3 mb-md-3'>

        <?php

        if(isset($_POST['pesquisar'])&&!empty($_POST['cxnome']))
        {
        $nome=$_POST['cxnome'];
        $stmt = $conn->prepare("select * from bn_publicacao where title like :letra");
        $stmt->bindValue(':letra', '%'.$nome.'%', PDO::PARAM_STR);
        $stmt->execute();
        $resultados = $stmt->rowCount();

          if($resultados>=1){ 

            while($reg = $stmt->fetch(PDO::FETCH_OBJ)){

            echo "<div class='card'>";

            echo "<div class='img-container'>"; 

            echo "<a href='index.php?post='"; 

            echo $reg->title." ";

            echo ">";

            echo "<img src='";

            echo $reg->capa." ";

            echo "'";

            echo "alt='";

            echo $reg->alt." ";

            echo "'";

            echo "class='card-img-top'";

            echo "id='imgUNcover'";

            echo ">";

            echo "</a>";

            echo "</div>";

            echo "<div class='card-body'>";

            echo "<a href='index.php?post='"; 

            echo $reg->title." ";

            echo "class='card-title cardTitleLink'>";

            echo "<h1 class='cardTitleUN'>";

            echo $reg->title." ";

            echo "</h1>";

            echo "</a>";

            echo "<p class='card-text text-muted'>";

            echo $reg->text." ";

            echo "</p>";

            echo "<a href='index.php?post='";

            echo $reg->title." ";

            echo "class='btn btn-outline-danger btn-sm'>";

            echo "Continue Lendo";

            echo "</a>";

            }

          }else{
            echo "Não existe usuario cadastrado";
            }

          }else{
            echo "Preencha o campo de pesquisa";
          }
          ?>

         </div>

      </div>

    </div>

</div>

enter image description here

They should be on this way:

enter image description here

This layout is from this code:

<div class="container my-3">

    <div class="row">

        <?php foreach ($dadosUN as $UN): ?>

           <div class="col-12 col-md-6 col-lg-3 mb-3 mb-md-3">

                <div class="card">

                    <div class="img-container">

                      <a href="index.php?post=<?php echo $UN['title']?>"><img src="<?php echo $UN['capa']?>" alt="<?php echo $UN['alt']?>" class="card-img-top" id="imgUNcover"></a>

                    </div>

                    <div class="card-body">

                      <a href="index.php?post=<?php echo $UN['title']?>" class="card-title cardTitleLink"><h1 class="cardTitleUN"><?php echo $UN['title']?></h1></a>

                      <p class="card-text text-muted"><?php echo $UN['text']?></p>

                      <a href="index.php?post=<?php echo $UN['title']?>" class="btn btn-outline-danger btn-sm">Continue Lendo</a>

                    </div>

                </div>

           </div>

       <?php endforeach; ?>

    </div>

</div>

How can i solve this problem? Would be better to put a foreach loop instead of while? And how can i do it?

Susi
  • 153
  • 1
  • 3
  • 11
  • you can't go mixing different mysql apis here. – Funk Forty Niner Sep 11 '18 at 19:22
  • @FunkFortyNiner So how can i put the results from the parameterized search input on my `foreach`? – Susi Sep 11 '18 at 19:26
  • This looks very close to code Sabrinia posted earlier. She was using `mysqli` which it also appears you are, you should see http://php.net/manual/en/mysqli.quickstart.prepared-statements.php. – user3783243 Sep 11 '18 at 19:28
  • @FunkFortyNiner Actually i'm not trying to know if i can mix apis, i just want to know how to solve my problem. – Susi Sep 11 '18 at 19:29
  • : "It looks like you're writing your own ORM. Have you considered using one that's already written, tested, and widely supported like [RedBeanPHP](https://redbeanphp.com/), [Doctrine](http://www.doctrine-project.org/), [Propel](http://propelorm.org/) or [Eloquent](https://laravel.com/docs/master/eloquent)?" – tadman Sep 11 '18 at 19:31
  • The problem is this code is both `mysqli` and PDO which is not ideal. What about using PDO exclusively? – tadman Sep 11 '18 at 19:32
  • @user3783243 This is our code, we both are trying to solve this, I know how to make the parameterized code works, but we need to put the result into a `foreach` instead of just a `print_r` or `echo`...etc. Is it possivel? – Susi Sep 11 '18 at 19:46
  • @user3783243 If not. How can i `echo` the results, on the html that i put on the question? – Susi Sep 11 '18 at 19:53
  • @tadman Check my comments please. – Susi Sep 11 '18 at 19:53
  • How does `DBRead` differ from `DBExecute` and why does the initial call bypass these functions? The set up is kinda strange here, and as noted you are mixing drivers so it can't function. – user3783243 Sep 11 '18 at 20:09
  • @user3783243 Check my edit, i got a "solution", and it's "working", this only works for the 1 result from the search input, the other results dont get the same layout, so as i said before, i need to put the results from the search code into a foreach loop, could you help me? – Susi Sep 11 '18 at 20:49

0 Answers0