column does not obey the Where command of an update

Asked

Viewed 62 times

3

I have a problem. At the moment I make an update, when I use Where only the line with the code informed is updated. however the Description field that I report, its content is replicated for all rows of the bank that is the only column that occurs. I’m using php with codeigniter

Follows the form:

            <h3> Descrição:</h3>
            <div class="form-group">
                <textarea name="descricao" id="texto">
                    <?php echo $evento[0]->cal_descricao ?>  
                </textarea>
            </div>

Follow the update function:

public function editar($id) {
    $data['cal_descricao'] = $this->input->post('descricao');
    $this->db->set('cal_descricao', $this->input->post('descricao'));
    $this->db->set('cal_titulo', $this->input->post('titulo'));
    $this->db->set('cal_estado', $this->input->post('estado'));
    $this->db->set('cal_pais', $this->input->post('pais'));
    $this->db->set('cal_dataEvento', $this->input->post('inicio'));
    $this->db->set('cal_dataTermino', $this->input->post('termino'));
    $this->db->set('cal_modalidades', $this->input->post('modalidades'));
    $this->db->where('cal_cod', $id);
    $this->db->update('v1_calendario');
    if ($this->db->update('calendario', $data)) {           
        $this->load->view('calendario/index');
        redirect('calendario/index');
    } else {
        redirect('calendario/index');
    }
}

Table html output:

 <tbody>
                 <tr>
                    <td>Evelinsss</td>
                    <td><p>vida</p></td>
                    <td>RJ Brazil</td>
                    <td>2016-06-05</td>
                    <td>2016-06-20</td>
                    <td>27</td>
                    <td><a href="http://localhost:8080/WAS/site/controle/calendario/atualizar/1">
                            <button type="button" class="btn btn-primary">Atualizar</button>
                        </a>
                    </td>

                </tr>
                                <tr>
                    <td>Evelin</td>
                    <td><p>vida</p>

RJ Brazil 2016-06-05 2016-06-20 27 Upgrade

The line update only the title of line one has been modified, but the description (result: life) occurs on the bottom line as well.

1 answer

2

I managed to fix! the problem was the update before the if:

 public function editar($id) {
    $data['cal_descricao'] = $this->input->post('descricao');
    $this->db->set('cal_descricao', $this->input->post('descricao'));
    $this->db->set('cal_titulo', $this->input->post('titulo'));
    $this->db->set('cal_estado', $this->input->post('estado'));
    $this->db->set('cal_pais', $this->input->post('pais'));
    $this->db->set('cal_dataEvento', $this->input->post('inicio'));
    $this->db->set('cal_dataTermino', $this->input->post('termino'));
    $this->db->set('cal_modalidades', $this->input->post('modalidades'));
    $this->db->where('cal_cod', $id);
    //        $this->db->update('v1_calendario'); - Removi essa linha
    if ($this->db->update('calendario', $data)) {           
        $this->load->view('calendario/index');
        redirect('calendario/index');
    } else {
        redirect('calendario/index');
    }
}

Browser other questions tagged

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