How do I show my list only the items that have user_id = {$ _ SESSION ['id']

1
<?php 
echo "<table class='table'>";
echo "<thead>";
echo "<tr>";
echo "<th>id</th>";
echo "<th>nome</th>";
echo "<th>descriçao</th>";
echo "<th>resquisito</th>";
echo "<th>previsao da data</th>";
echo "<tbody>";
echo "</thead>";
echo "<tbody>";
echo "<tbody id='table_page'>";

foreach ($tarefas as $taf ) {
  echo "<tr>";
  echo "<td style='padding-right:10px'>" .$taf->tarefa_id . "</td>";
  echo "<td>" . $taf->tarefa_nome . "</td>";
  echo "<td>" . $taf->tarefa_descricao . "</td>";
  echo "<td>" . $taf->tarefa_minimo . "</td>";
  echo "<td>" . $taf->tarefa_data . "</td>";
  echo "<td align='center'> <span name='opc' id='visualizar'  data-target='#gridSystemModal'  ><i class='fa fa-cog' aria-hidden='true'></i></span></td>";
}
?>  


public function index($indice=null) {
    $this->load->database();
    $this->db->select('*');
    $dados['tarefas'] = $this->db->get('tarefa')->result();
    $this->load->view('includes/html_header');
    $this->load->view('includes/menu');
    $this->load->view('listadetarefasv', $dados);
    $this->load->view('includes/html_footer');
}
}

How do I make my list show only items that have usuario_id={$_SESSION['id'] .

    
asked by anonymous 26.09.2017 / 12:24

1 answer

1

I believe that adding an if before table printing solves your problem.

Assuming that the record has the value inside the user id:

  foreach ($tarefas as $taf ) {
      if($taf->usuario_id == {$_SESSION['id']){
        echo "<tr>";
        echo "<td style='padding-right:10px'>" .$taf->tarefa_id . "</td>";
        echo "<td>" . $taf->tarefa_nome . "</td>";
        echo "<td>" . $taf->tarefa_descricao . "</td>";
        echo "<td>" . $taf->tarefa_minimo . "</td>";
        echo "<td>" . $taf->tarefa_data . "</td>";
        echo "<td align='center'> <span name='opc' id='visualizar'  data-target='#gridSystemModal'  ><i class='fa fa-cog' aria-hidden='true'></i></span></td>";
      }
    }
    ?>  

See if this works.

    
26.09.2017 / 13:29