CodeIgniter update works but wrong list

0

I'm having a problem updating a bank record by codeigniter, I have two tables, one call:

Employee (where employees are stored in the company and in which sector that employee works, this table has the foreign key of the sector table (sector_id)

And the other call:   sector (where it stores the company sectors)

I can update the information by the forms without error, even updates in the bank also, however, the listing in the system shows the employee's old sector and not the newly updated one, for example:

João da silva - Collection, I update for administration (updates the bank the new sector) when I give the redirect for the listing of the system and João da Silva is still in the collection sector.

Employee template code, where I join the tables (sector and employee), to show the names of the sectors of the system listing

public function ListarEmpregado(){
$this->db->select('e.id_empregado, e.nome_empregado,e.salario, s.nome');
$this->db->from('empregado as e');
$this->db->join('setor as s','s.id_setor = e.id_empregado');
$this->db->order_by('nome_empregado');
$query = $this->db->get();
return $query->result();
}

Employee update code (employee model):

public function atualizarinfosempregado($id,$array){
    $this->db->where('id_empregado',$id);
    $this->db->update('empregado',$array);  
}

Listing (index_company.php):

<?php foreach($empregado as $e){ ?>
        <tr>
            <td><?php echo $e->id_empregado ?></td>
            <td><?php echo $e->nome_empregado ?></td>
            <td><?php echo $e->salario ?></td>
            <td><?php echo $e->nome ?></td>
            <td><a href="#" class="empregado" id="<?php echo $e->id_empregado; ?>">Deletar</a></td>
            <td><a href="http://localhost/CodeIgniter-3.1.3/CodeIgniter-3.1.3/index.php/IndexController/idempregado/<?php echo $e->id_empregado; ?>">Atualizar</a></td>
        </tr>

What is missing? Thanks for the help:)

    
asked by anonymous 20.03.2017 / 03:38

1 answer

1

Your problem is in the join that is being done in the query, you are doing the join of id_setor with id_empregado , below how it should be done:

public function ListarEmpregado(){
    $this->db->select('e.id_empregado, e.nome_empregado,e.salario, s.nome');
    $this->db->from('empregado as e');
    $this->db->join('setor as s','s.id_setor = e.id_setor');
    $this->db->order_by('nome_empregado');
    $query = $this->db->get();
    return $query->result();
}
    
20.03.2017 / 13:55