Bootstrap with loop

Asked

Viewed 85 times

-1

Good evening person!!

Someone can help me?

I’m trying to make a zebra table but the lines aren’t getting different colors, gray and white. I have a while in the 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>";
  ?>

inserir a descrição da imagem aqui

Can someone help me identify where the mistake is??

Thank you.

2 answers

0


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

Put the echo "<tbody>"; before the 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>";
  ?>

0

Pass only the lines 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>

Browser other questions tagged

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