session comparison with a php database field

Asked

Viewed 53 times

0

I need some help. I have a table in the bank called texts that in turn has a student column that gets emails from those who are saving texts there. On this page below a table has to be generated for each student’s text of that particular email, that is, I have to compare the email saved in the session with the emails of the student column of the table texts and generate tables only for the student texts of that specific email. But I don’t know if I did right in that if inside the while. They can help me?

<?php require_once ("cabecalho2.php");
    require_once ("../model/banco-usuario.php");
    session_start();
    $consulta = "SELECT titulo, data, aluno FROM textos";
    $result = $conexao->query($consulta);
    ?>

    <main>
        <div class="row">
            <?php while($dados = $result->fetch_array()){
                $titulo = $dados["titulo"];
                $data = $dados["data"];
                $aluno = $dados['aluno'];
                if($_SESSION('login') = $aluno;){

                    $tabela ='<div class="col l10 s11 offset-s1" style="border: #006064 solid 3px; padding: 0px; border-radius: 6px; margin-bottom: 10px;">';
                    $tabela .= '<div class="card-panel cyan darken-4 z-depth-0" style="margin-top: 0px; border-radius: 0px; margin-bottom: 0px; padding: 3px 9px 3px 9px;">';
                    $tabela .= '<h5 class="white-text light center-align" style="margin: 6px; font-size: 18px;">Tema:';
                    $tabela .= '</h5>';
                    $tabela .= '</div>';
                    $tabela .= '<div class="card-panel N/A transparent z-depth-0 col l12 s12" style="padding: 10px; margin: 0px;">';
                $tabela .= '<table class="highlight centered">';//abre table
                $tabela .='<thead>';//abre cabeçalho
                $tabela .= '<tr>';//abre uma linha
                $tabela .= '<th>Título da Redação</th>'; // colunas do cabeçalho
                $tabela .= '<th>Status da Correção</th>';
                $tabela .= '<th>Data de Envio</th>';
                $tabela .= '<th>Prazo de Entrega</th>';
                $tabela .= '<th>Ação</th>';
                $tabela .= '</tr>';//fecha linha
                $tabela .='</thead>'; //fecha cabeçalho
                $tabela .='<tbody>';//abre corpo da tabela
                /*Se você tiver um loop para exibir os dados ele deve ficar aqui*/
                $tabela .= '<tr>'; // abre uma linha
                $tabela .= '<td>'.$titulo.'</td>'; //coluna numero
                $tabela .= '<td>Corrigida</td>'; // coluna validade
                $tabela .= '<td>'.$data.'</td>'; //coluna anexo
                $tabela .= '<td>15 dias</td>';//coluna valor numero
                $tabela .= '<td><i class="small material-icons">done</i></td>'; // coluna data
                $tabela .= '</tr>'; // fecha linha
                /*loop deve terminar aqui*/
                $tabela .='</tbody>'; //fecha corpo
                $tabela .= '</table>';//fecha tabela
                $tabela .= '</div>';
                $tabela .= '</div>';

                echo $tabela;
            }
        }?>

    </div>
    </main>

    <?php include 'rodape.php';
    die();?>

1 answer

0

I don’t understand very well, do you want to take only the emails of the student in question? (What is logged in?)

If it is, try to do something like:

$consulta = "SELECT titulo, data, aluno FROM textos WHERE aluno = '".$_SESSION['login']."'";

Remove this line too, after all, we pass the comparison in the bank search

if($_SESSION('login') = $student;){

Don’t forget to remove the remaining } .

NOTE: I imagine that what is stored in the login session is what will compare in the bank, if not, change to the correct one

  • That’s what it was. Thank you very much.

Browser other questions tagged

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