Fill table with database data. (Mysql and Bootstrap 4.1)

Asked

Viewed 2,632 times

-1

Save people, I’m trying to fill a table with data coming directly from the database (Mysql). I’m new to the web, I managed to put together a sketch of what I’m trying to do. If anyone can give some tips, I would be extremely grateful.

<?php 
include "conexao.php" ;
$sql = "Select * from usuario";
$resultado = mysqli_query($con,$sql); ?>

 <table class="table">
  <thead class="thead-dark">
    <tr>
      <th scope="col">#</th>
      <th scope="col">email</th>
      <th scope="col">senha</th>
     
    </tr>
  </thead>

<?php 
while($dados = mysqli_fetch_array($resultado)){
  $email = $dados['email'];
  $senha = $dados['senha']; ?>
 
  <tbody>
    <tr>
      <th scope="row"></th>
      <td><?php $email ?></td>
      <td><?php $senha ?></td>
     
    </tr> 
      </tbody>
</table>
  
   <?php } ?>

  </div>

That part of the table and the bank.

  • Good afternoon, what’s the mistake?

  • 2

    at first on these lines are speaking the echo. <td><?php echo $email ?></td>&#xA; <td><?php echo $senha ?></td>

  • At first I thought that leaving this <tr> </tr> part inside the WHILE, the lines would be filled in, but not filled in. In the best case I had, only the first row was created and filled.

  • I added an image of the return that the code generates.

  • My friend, the data is below, the problem is in the closing of your tags html..the tbody must be outside the while and the closing of tags also, within the while should be just the <tr> and <td>

  • I added it as an answer, just to help you

Show 1 more comment

1 answer

2

My friend, the data is below, the problem is in the closing of your tags html..the tbody must be outside the while and the closing of tags also, within the while should be just the <tr> and <td>

 <table class="table">
  <thead class="thead-dark">
    <tr>
      <th scope="col">#</th>
      <th scope="col">email</th>
      <th scope="col">senha</th>

    </tr>
  </thead>
<tbody>
<?php 
while($dados = mysqli_fetch_array($resultado)){
  $email = $dados['email'];
  $senha = $dados['senha']; ?>
 <tr>
      <th scope="row"></th>
      <td><?php $email ?></td>
      <td><?php $senha ?></td>

    </tr> 
 <?php } ?>
 </tbody>
</table>
  </div>
  • Po, mano, era isso msm. A mere detail that made me waste an absurd time. Muito muito obrigado, mesmo. =)

  • You’re welcome @Pierryrodrigues if you can mark the answer as correct.

Browser other questions tagged

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