How do I create a caption that shows the contents of the column in the database?

Asked

Viewed 26 times

1

I created a table that displays all registered employees in the database, I wanted to use the attribute title within the <td> to create a exact legend of what is inside the table columns.

Ex: While dragging the mouse in the column Name field João the legend would show João instead of [nome].

The line I’m talking about is:

echo '<td title="[nome]">'.$exibir_colunas['nome'].'</td>';
<?php
        require_once '../conexao/conexao.php';

        try {
            $selecao = "SELECT * FROM funcionario";
            $seleciona_dados = $conexao->prepare($selecao);
            $seleciona_dados->execute();
            $linhas = $seleciona_dados->fetchAll(PDO::FETCH_ASSOC);
        } catch (PDOException $falha_selecao) {
            echo "A listagem de dados não foi feita".$falha_selecao->getMessage();
            die;
        } catch (Exception $falha) {
            echo "Erro não característico do PDO".$falha->getMessage();
            die;
        }
    ?>
    <table border="1">
        <tr> 
            <th title="ID"> ID </th> 
            <th title="Nome"> Nome </th> 
            <th title="Cargo"> Cargo </th>
            <th title="CPF"> CPF </th> 
            <th title="Telefone"> Telefone </th>
            <th title="Email"> Email </th>
            <th title="Ações"> Ações </th>
        </tr>
        <?php 
            foreach ($linhas as $exibir_colunas){
                echo '<tr>';
                echo '<td title="[cd_funcionario]">'.$exibir_colunas['cd_funcionario'].'</td>';
                echo '<td title="[nome]">'.$exibir_colunas['nome'].'</td>';
                echo '<td title="[cargo]">'.$exibir_colunas['cargo'].'</td>';
                echo '<td title="[cpf]">'.$exibir_colunas['cpf'].'</td>';
                echo '<td title="[telefone]">'.$exibir_colunas['telefone'].'</td>';
                echo '<td title="[email]">'.$exibir_colunas['email'].'</td>';
                echo '<td>'."<a href='../crud/form_insert_funcionario.php' title='Cadastrar funcionário'>INSERT</a> ".
                "<a href='../crud/form_select_funcionario.php' title='Listar funcionários'>SELECT</a> ".
                "<a href='../crud/form_update_funcionario.php' title='Atualizar funcionário'>UPDATE</a> ".
                "<a href='../crud/form_delete_funcionario.php' title='Deletar funcionário'>DELETE</a>".'</td>';
                echo '</tr>'; echo '</p>';
            }
        ?>
    </table>
  • Ué, just put $display_columns['name'] instead of [name] that is in the title inside the foreach. Like you did to appear Jun on td

1 answer

0


echo '<td title="'.$exibir_colunas['nome'].'">'.$exibir_colunas['nome'].'</td>';
  • 1

    Thank you, man, you helped me with my doubt.

Browser other questions tagged

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