Guilherme R
Guilherme R

Reputation: 525

How do I display MySQL data in rows?

So I have a code in PHP to display MySQL database information. This is the PHP code:

<?php
$servidor = mysqli_connect ("localhost","root","");
mysqli_select_db($servidor, "produtos");

if (isset($_GET['texto'])) {
    $pesquisa = $_GET['texto'];
    $query = mysqli_query($servidor, "SELECT * FROM produtos WHERE Nome LIKE '%$pesquisa%' OR Referencia LIKE '%$pesquisa%'");

    if(mysqli_num_rows($query) > 0) {
        while($resultados = mysqli_fetch_array($query)) {
            echo "<h3>Nome: ".$resultados['Nome']."</h3>Referência: ".$resultados['Referencia']."";
        }
    } else {
        echo "<h3>Não foram encontrados resultados!</h3>";
    }
}
?>

But right now, that information is displayed in one single line, like this:

enter image description here

and I want to display it in rows, like this:

enter image description here

How can I do this in PHP?

Thank you

Upvotes: 0

Views: 81

Answers (2)

Joe Eig
Joe Eig

Reputation: 353

You might consider using the new column attributes introduced by CSS 3.

Example:

p {
  column-count: 3;
  column-width: 50px;
}
<!doctype html>
<html lang="de">

<body>
  <p>
    First column
  </p>
  <p>
    Second column
  </p>
  <p>
    Third column
  </p>
</body>

</html>

Upvotes: 1

GasKa
GasKa

Reputation: 663

This part can be achieved usign HTML + CSS as @Bernhard said. Or, something that I DON'T RECOMMEND, like this:

<div style="width:25%;float:left;padding:10px;">{item}</div>

Upvotes: 0

Related Questions