Create HTML list with SQL query return

0

I need to return the SQL query in an HTML list. In the case I need to line up with "affiliate" and "name", the query below, has correctly returned the requested data, but I need now to put this data one after another in an HTML

//iniciando a conexão com o banco de dados
$cx = mysqli_connect("localhost", "root", "");

//selecionando o banco de dados
$db = mysqli_select_db($cx, "dados");

//criando a query de consulta à tabela criada
$sql = mysqli_query($cx, "SELECT * FROM esocial") or die(
    mysqli_error($cx) //caso haja um erro na consulta
);

//pecorrendo os registros da consulta.
while($aux = mysqli_fetch_assoc($sql))
{
    echo "-----------------------------------------<br />";
    echo "Filial:".$aux["filial"]."<br />";
    echo "CPF:".$aux["cpfTrab"]."<br />";
    echo "PIS:".$aux["nisTrab"]."<br />";
    echo "Sexo:".$aux["sexo"]."<br />";
    echo "Raça/Cor:".$aux["racaCor"]."<br />";
    echo "Estado Civil:".$aux["estCiv"]."<br />";
    echo "Grau Instrução:".$aux["grauIntr"]."<br />";
    echo "Data Nascimento:".$aux["dtNascto1"]."<br />";
    echo "Cod. Município:".$aux["codMunic1"]."<br />";
    echo "UF:".$aux["uf1"]."<br />";
    echo "País Nascimento:".$aux["paisNascto"]."<br />";
    echo "País Nacionalidade:".$aux["paisNac"]."<br />";
    echo "Nome Mãe:".$aux["nmMae"]."<br />";
    echo "Nome Pai:".$aux["nmPai"]."<br />";
}
    
asked by anonymous 03.03.2018 / 05:39

1 answer

0

Before the forech you open the list <ul> or <ol> , inside puts the data between <li> </li> and then closes </ul> or </ol> :

echo "<ul>";
while($aux = mysqli_fetch_assoc($sql)) {
    echo "<li> Filial:".$aux["filial"]." - Nome: ".$aux["nome"]."</li>";
}
echo "</ul>";

To show in a table, just change the HTML tags:

<table>
    <colgroup>
        <col width="25%">
        <col width="50%">
        <col width="25%">
    </colgroup>
    <thead>
        <tr>
            <th>Nome</th>
            <th>CPF</th>
            <th>...</th>
        </tr>
    <thead>
    <tfoot>
        <tr>
            <td>Nome</td>
            <td>CPF</td>
            <td>...</td>
        </tr>
    <tfoot>
    <tbody>
        <?php
            while($aux = mysqli_fetch_assoc($sql)) {
                echo "
                    <tr>
                        <td>".$aux["nome"]."</td>
                        <td>".$aux["cpf"]."</td>
                        <td>".$aux["..."]."</td>
                    </tr>
                ";
            }
        ?>
    </tbody>
</table>

thead set table header, tbody table body, tfoot table footer and colgroup set column height (you can change other HTML attributes, in case I just used to set the column width)

That?

    
03.03.2018 / 05:46