Create Table with 3 rows then create another table with 3 more rows

Asked

Viewed 125 times

1

I would like to create several tables with three lines each. Example:

GROUP A

TEAM 1

TEAM 2

TEAM 3

GROUP B

TEAM 4

TEAM 5

TEAM 6

Follow my code:

<?php include 'masterpage.php'; 
      include 'conexao.php'; 

$sql = "SELECT G.NOME_CHAVE, G.ID_EQUIPE, E.ID_EQUIPE, E.NOME
FROM Grupos_Sorteados AS G
INNER JOIN Equipe AS E
ON G.ID_EQUIPE = E.ID_EQUIPE
ORDER BY NOME_CHAVE";
$resultado = mysqli_query($conn, $sql); 

?>

<div id="tab" class="row">

<div class="col-sm-6">     
   <div class="table-responsive" style="font-size: 14px !important;">
   <p>Grupo: <?php echo $chave?> </p>
    <table id="tabelaEquipe" class="table table-borderless table-striped table-earning">
      <?php 

while($dados = mysqli_fetch_array($resultado)){
   $chave = $dados['NOME_CHAVE'];
   $equipe = $dados['NOME'];    
  ?>   <thead>
            <tr>
               <th>Equipe</th>
               <th>Chave</th>

            </tr>
         </thead>
   <tbody>
    <tr>
      <td><?php echo $equipe ?></td>
      <td><?php echo $chave?></td>

    </tr> 
  </tbody><?php } ?>
      </table>
   </div>
</div> 

[![inserir a descrição da imagem aqui][1]][1]

<script>
function editarEquipe(){
$dados = mysqli_fetch_array($resultado)
var nome = <?php echo $nome ?>;
}
</script>

<?php include 'footer.php'; ?>

EDIT*

I got the following result, but it’s still not what I expect. I need to put 3 teams inside a table only. Can someone give me a light?

inserir a descrição da imagem aqui

1 answer

2


Perform a query in your database using distinct (https://www.w3schools.com/sql/sql_distinct.asp) to pull all groups.

SELECT DISTINCT NOME_CHAVE FROM Grupos_Sorteados

We will have an array with all the groups of the championship, just play it within a foreach and within it perform a select searching for teams of that group. You can take advantage of this SQL command just by adding at the end:

WHERE G.NOME_CHAVE = {{ aqui vem a variavel com nome do grupo do foreach }}

I think it would look something like this:

<?php foreach($grupos as $grupo): ?>
<p>Grupo: <?php echo $grupo["NOME_CHAVE"] ?> </p>
<table id="tabelaEquipe" class="table table-borderless table-striped table-earning">
    <thead>
        <tr>
            <th>Equipe</th>
        </tr>
    </thead>
    <tbody>
    <?php
    $sql = "SELECT E.ID_EQUIPE, E.NOME
    FROM Grupos_Sorteados AS G
    INNER JOIN Equipe AS E
    ON G.ID_EQUIPE = E.ID_EQUIPE 
    WHERE G.NOME_CHAVE = {$grupos}";
    $resultado = mysqli_query($conn, $sql); 
    while($dados = mysqli_fetch_array($resultado)):    
    ?>   
        <tr>
            <td><?= $dados['NOME'] ?></td>
        </tr> 
    <?php endwhile; ?>
    </tbody>
</table>
<?php endforeach; ?>

A suggestion is to then place the dots on the side of the team name.

  • It worked! Thanks for the help.

  • I’m glad I could help.

Browser other questions tagged

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