How do I not repeat the header of the table over and over again.?

I have the problem that every time I have a record the header of the table is repeated, how do I eliminate that?

enter image description here

I attach my code.

if(isset($_POST['btn1'])){
 
  $resultado = mysqli_query($con,"SELECT * FROM estudiante");
  
  while($consulta = mysqli_fetch_array($resultado)){
    
    echo
      "
      <link rel=\"stylesheet\" type=\"text/css\" href=\"styles/styleTable.css\">
      <body>
    <div id=\"wrapper\">
     <h1>Registro De Alumnos</h1>
     
     <table id=\"keywords\" cellspacing=\"0\" cellpadding=\"0\">
       <thead>
         <tr>
           <th><span>Nombres y Apellidos</span></th>
           <th><span>Cedula</span></th>
           <th><span>Cod. Matricula</span></th>
           <th><span>Telefono</span></th>
           <th><span>Correo</span></th>
           <th><span>Direccion</span></th>
           <!--Se puede segui aunmentando aqui las columnas :D-->
         </tr>
       </thead>
       <tbody>
         <tr>
           <td class=\"lalign\"> ".$consulta['NombresApellidos']."</td>
           <td>".$consulta['Cedula']."</td>
           <td>".$consulta['CodigoMatricula']."</td>
           <td>".$consulta['Telefono']."</td>
           <td>".$consulta['Correo']."</td>
           <td>".$consulta['Direccion']."</td>
         </tr>
       </tbody>
     </table>
    </div> 
   </body>
      
      ";
  }



}

In your code, the header is inside the loop, as is a lot of other stuff which is not visible in the output, but still is unneccessarily repeated (body opening tag, wrapper div opening tag, table opening tag, the whole table header – everything except the table rows and cells), producing invalid HTML code. Same for the closing tags of tbody, table, wrapper div and body.

Move all that out of the loop :

 echo
      "
      <link rel=\"stylesheet\" type=\"text/css\" href=\"styles/styleTable.css\">
      <body>
    <div id=\"wrapper\">
     <h1>Registro De Alumnos</h1>
     
     <table id=\"keywords\" cellspacing=\"0\" cellpadding=\"0\">
       <thead>
         <tr>
           <th><span>Nombres y Apellidos</span></th>
           <th><span>Cedula</span></th>
           <th><span>Cod. Matricula</span></th>
           <th><span>Telefono</span></th>
           <th><span>Correo</span></th>
           <th><span>Direccion</span></th>
           <!--Se puede segui aunmentando aqui las columnas :D-->
         </tr>
       </thead>
       <tbody>
"
if(isset($_POST['btn1'])){
 
  $resultado = mysqli_query($con,"SELECT * FROM estudiante");
  
  while($consulta = mysqli_fetch_array($resultado)){
    
   echo "

         <tr>
           <td class=\"lalign\"> ".$consulta['NombresApellidos']."</td>
           <td>".$consulta['Cedula']."</td>
           <td>".$consulta['CodigoMatricula']."</td>
           <td>".$consulta['Telefono']."</td>
           <td>".$consulta['Correo']."</td>
           <td>".$consulta['Direccion']."</td>
         </tr>
    
      
      ";
  }

echo "
   </tbody>
     </table>
    </div> 
   </body>
";

}