<?php
$servidor = "localhost";
$usuario = "kaltekgo_painel";
$senha = "painel@2024";
$dbname = "kaltekgo_painel";

$conn = mysqli_connect($servidor, $usuario, $senha, $dbname);
if (!$conn) {
    die("Conexão falhou");
}

$sql = "SELECT professor.*, s.* 
        FROM professor 
        INNER JOIN (
            SELECT idProfessor, MAX(id) AS id 
            FROM senhasPainelFundamental 
            GROUP BY idProfessor
        ) AS s_max ON professor.idProfessor = s_max.idProfessor 
        INNER JOIN senhasPainelFundamental s ON s.id = s_max.id 
        WHERE s.status = 'ativo' 
        ORDER BY s.id DESC, s.nomeProfessor ASC
        LIMIT 7 OFFSET 1";

$result = mysqli_query($conn, $sql);

while ($row = mysqli_fetch_assoc($result)) {
    echo "<tr>
            <td>{$row['senha']}</td>
            <td>{$row['nomeProfessor']} / {$row['disciplinaSeries']}</td>
            <td>{$row['salaProfessor']}</td>
          </tr>";
}
