Presentation of the php query

3

I need to help me create a function in php that lists multiple tables in a row with multiple columns, depending on the amount of records in the database and the spacing of the tables defined by <div class="span">

This is my role, but it's just listing in multiple rows with a single column:

<?php
require 'conexao.php';
$result = mysqli_query($con, 'select * from homem_classic');
?>
<?php $titulo ="Homem Clássico";
include 'includes/header.php';
include 'includes/footer.php';
?>
<!DOCTYPE html>
<html lang="pt-PT">
<head>
    <meta charset="UTF-8">
</head>
<body>
<div class="row-fluid">
        <div class="span3">
<div class="imagens">
<table class="tabela">

<?php while ($product=mysqli_fetch_object($result)) { ?>

<tr>
    <td><img src="<?php echo $product->imagem; ?>" alt=""></td>
</tr>       
<tr>
    <td><?php echo $product->nome; ?></td>
</tr>
<tr>
<td><?php echo $product->descricao; ?></td>
</tr>
<tr>
<td>    
<p><a class="btn btn-info" href="cart.php?id=<?php echo $product->id; ?>"><?php echo $product->preco; ?><i class="icon-shopping-cart"></i></a></p>
    </td>
    </tr>
<?php } ?>
</table>
    </div>
</div>
</div>
</body>
</html>
    
asked by anonymous 11.06.2016 / 10:52

1 answer

6

A table is created using TR to open rows and TD to open cells.

A TR with multiple TD is what you want:

<?php
while ($product=mysqli_fetch_object($result)) { ?>

<tr>
  <td><img src="<?php echo $product->imagem; ?>" alt=""></td>
  <td><?php echo $product->nome; ?></td>
  <td><?php echo $product->descricao; ?></td>
  <td><p><a class="btn btn-info" href="cart.php?id=<?php echo $product->id; ?>"><?php echo $product->preco; ?><i class="icon-shopping-cart"></i></a></p></td>
</tr>

<?php } ?>

Example tables:

<h4>Linha com uma células</h4>
<table>
  <tr>
    <td>João</td>
  </tr>
  <tr>
    <td>Azul</td>
  </tr>
  <tr>
    <td>Joana</td>
  </tr>
  <tr>
    <td>Rosa</td>
  </tr>
</table>

<h4>Linha com múltiplas células</h4>
<table>
  <tr>
    <td>João</td>
    <td>Azul</td>
  </tr>
  <tr>
    <td>Joana</td>
    <td>Rosa</td>
  </tr>
</table>
    
11.06.2016 / 13:39