Bootstrap with loop

0

Good evening person !!

Can anyone help me?

I'm trying to make a zebra table but the lines are not getting different colors, gray and white. I have a while in code, using php.

      <div class="container" id="container">
    <h2>Ambientes Monitorados de <?php echo $nome_equipe?></h2>
    <table class="table table-striped">
      <thead>
        <tr>
          <th>Ambiente</th>
          <th>Solução</th>
          <th>Criação</th>
          <th>Ultima Atualização</th>
          <th>Criador</th>
        </tr>
      </thead>
  <?php $sql = mysqli_query($conn, "SELECT nome_ambiente, solucao_ambiente, dt_criacao_ambiente, dt_last_update_ambiente, nome_equipe FROM tb_ambientes LEFT JOIN tb_equipes ON tb_ambientes.id_equipe = tb_equipes.id_equipe WHERE id_user = '$id_user'");
    while($exibe = mysqli_fetch_assoc($sql)){
  echo "<tbody>";
  echo "<tr><td>" . $exibe["nome_ambiente"] . "</td><td>" . $exibe["solucao_ambiente"] . "</td><td>" . $exibe["dt_criacao_ambiente"] . "</td><td>" . $exibe["dt_last_update_ambiente"] . "</td><td>" . $nome_user . "</td></tr>";
  }
  echo "</tbody>"
        . "</table>"
        . "</div>";
  ?>

Can anyone help me identify where the error is ??

Thank you.

    
asked by anonymous 15.09.2018 / 23:32

2 answers

0

You are repeating <tbody> within the while, so the class will not have the expected effect because the table will have multiple <tbody> with only 1 row.

Put echo "<tbody>"; before while:

<?php $sql = mysqli_query($conn, "SELECT nome_ambiente, solucao_ambiente, dt_criacao_ambiente, dt_last_update_ambiente, nome_equipe FROM tb_ambientes LEFT JOIN tb_equipes ON tb_ambientes.id_equipe = tb_equipes.id_equipe WHERE id_user = '$id_user'");
  echo "<tbody>"; // ANTES DO WHILE
  while($exibe = mysqli_fetch_assoc($sql)){
      echo "<tr><td>" . $exibe["nome_ambiente"] . "</td><td>" . $exibe["solucao_ambiente"] . "</td><td>" . $exibe["dt_criacao_ambiente"] . "</td><td>" . $exibe["dt_last_update_ambiente"] . "</td><td>" . $nome_user . "</td></tr>";
  }
  echo "</tbody>"
        . "</table>"
        . "</div>";
  ?>
    
16.09.2018 / 02:46
0

Pass only the rows in the loop

<div class="container" id="container">
    <h2>Ambientes Monitorados de <?php echo $nome_equipe?></h2>
    <table class="table table-striped">
      <thead>
        <tr>
          <th>Ambiente</th>
          <th>Solução</th>
          <th>Criação</th>
          <th>Ultima Atualização</th>
          <th>Criador</th>
        </tr>
      </thead>
 <tbody>
  <?php $sql = mysqli_query($conn, "SELECT nome_ambiente, solucao_ambiente, dt_criacao_ambiente, dt_last_update_ambiente, nome_equipe FROM tb_ambientes LEFT JOIN tb_equipes ON tb_ambientes.id_equipe = tb_equipes.id_equipe WHERE id_user = '$id_user'");
    while($exibe = mysqli_fetch_assoc($sql)){
  echo "<tr><td>" . $exibe["nome_ambiente"] . "</td><td>" . $exibe["solucao_ambiente"] . "</td><td>" . $exibe["dt_criacao_ambiente"] . "</td><td>" . $exibe["dt_last_update_ambiente"] . "</td><td>" . $nome_user . "</td></tr>";
  }

  ?>
  </tbody>
 </table>"
</div>
    
16.09.2018 / 03:20