Presentation of the php query

Asked

Viewed 49 times

3

I need you to help me create a php function 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">

That’s my job, but she’s just listing in multiple lines 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>
  • Put the php part too, how to fetch the data?

1 answer

6

One table is created using TR to open lines and TD to open cells.

One TR multi-purpose 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>

  • 4

    Le @Zuul is back!

Browser other questions tagged

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