How to list data from one table, even the other (INNER JOIN) being empty?

Asked

Viewed 142 times

1

On my page index, own a input search for the user to search the data in the database, this input calls this method in the Controller:

public function pesquisar() 
{     
        $this->load->model('Processo_model', 'processo');
        $dados['processo'] = $this->processo->get_processos_like();
        if (!$this->processo->get_processos_like()) 
        {          
            $this->load->view('/listar/listar_processo', $dados);
        } else {
            redirect('dashboard', 'refresh');
        }
}

In the model is thus the method code:

function get_processos_like() 
{
        $termo = $this->input->post('pesquisar');
        $this->db->join('andamento', 'fkcodprocesso=codprocesso', 'inner');
        $this->db->select('*');
        $this->db->where('nprocesso', $termo);
        return $this->db->get('processo')->result();
}  

And in the view, it’s like this:

<?php foreach ($processo as $proc) { ?>
<table>
<tr class="row">                                
<td><?= $proc->dtandamento; ?></td>
<td><?= $proc->descricao; ?></td>
</tr> 
<?php } ?>                    
</table>

What happens is that when the process (from the Processes table) still has no movements (from the Andamentos table), the search returns me null, or does not return anything. I would like you to display the process data even though it has no recorded progress.

I’ve tried using the LEFT JOIN but it didn’t work out.

1 answer

2


In place of inner in the last method parameter $this->db->join place left, example:

function get_processos_like() 
{
        $termo = $this->input->post('pesquisar');
        $this->db->join('andamento', 'fkcodprocesso=codprocesso', 'left');
        $this->db->select('*');
        $this->db->where('nprocesso', $termo);
        return $this->db->get('processo')->result();
}  

References

  • That way the process data appear, but gives problem in my Modal Add Tempo that has within the Process view, understood?

  • @Ramiro you asked one thing in the question, what happens in the form is another consequence of the change, to bring data from the table of the left is how it does, and this was stipulated in the question, but, what problem happens now?

  • Modal even adds the progress in the database, but arrow the fkcodprocesso with the value '0'; ...that is, it loses the $id reference of the process, I don’t know why.

  • @Ramiro there you agree that is another problem, and is not what is in the question? see here we help what is in the question and only ratifying bring data from the table on the left and if there is something in the table on the right is how it does, the problem of losing the $id you have to look at what you’re carrying in your view!

  • Okay, thank you, I’ll mark as accepted, but if you can help me with that detail I appreciate.

  • the modal view looks like this: <form action="<?= base_url() ? >tempo/register" method="post"> <input type="Hidden" id="fkcodprocesso" name="fkcodprocesso" value="<?= $process[0]->fkcodprocess; ?>">

  • @Ramiro leia https://answall.com/editing-help

Show 2 more comments

Browser other questions tagged

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