Does anyone know what I have to do on this table so it does not get crooked like that?

0

foreach($registroas$reg){echo"
<table class='centered' >
<thead>
<tr>
<th>Nome</th>
<th>Telefone</th>
<th>Email</th>
</tr>
</thead>";
    echo "<tbody>";
    echo "<tr>";
    echo "<td>".$reg['nome']."</td>";
    echo "<td>".$reg['telefone']."</td>";
    echo "<td>".$reg['email']."</td>";
    echo "</tr>";
    echo "</tbody>";
    echo "</table>";
}
    
asked by anonymous 03.07.2018 / 23:35

1 answer

9

The problem is that you are creating several independent tables (look at the source of your page to understand better).

Take the structure of the loop table so you have several rows in the same table:

<table class='centered' >
   <thead>
      <tr>
         <th>Nome</th>
         <th>Telefone</th>
         <th>Email</th>
      </tr>
   </thead>
   <tbody>
<?php
    foreach ($registro as $reg){
    echo "\t\t<tr>";
    echo "\t\t\t<td>".$reg['nome']."</td>";
    echo "\t\t\t<td>".$reg['telefone']."</td>";
    echo "\t\t\t<td>".$reg['email']."</td>";
    echo "\t\t</tr>";
}
?>
   </tbody>
</table>
Note that I've added some \t to echo to indent, you do not have to do this, and if you do, put whatever you need to align right with the rest of the HTML (to help you understand). The \t is the tab character, you can change it by whitespace.

    
03.07.2018 / 23:37