Codeigniter update works but wrong list

Asked

Viewed 156 times

0

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

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

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

I can update the information by the forms without error, including updates in the bank also, however, the listing in the system shows the old sector of the employee and not the new recently updated, for example:

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

Code of the model employed, 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(employed template):

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>

I wonder what’s missing? Thanks for your help :)

1 answer

2

Your problem is in the Join that is being done in consultation, you are doing the Join of id_setor with id_empregado, goes down as 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();
}
  • It worked, it was a very silly mistake Thank you very much

Browser other questions tagged

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