0

问题

如何在 Codeigniter 中一次更新 3 个表?我早些时候这样做了,但这种情况有点不同,我现在被困了两天。

我有 3 个要更新的表。

我不知道如何使用连接表更新 3 个表。我的模型如下所示:

function edit_aanbieding($data, $image_data)
{
    $id = $this->uri->segment(3);
    $this->db->update('Aanbiedingen', $data); 
    $insertfoto = array(
        'fotonaam' => $image_data['file_name']
    );
    $this->db->join('Aanbiedingen', 'bedrijfaanbiedingen.idaanbiedingen = Aanbiedignen.idaanbiedingen');
    $this->db->join('fotoaanbiedingen', 'bedrijfaanbiedingen.idfotoaanbiedingen = fotoaanbiedingen.idfotoaanbiedingen');
    $this->db->where('idbedrijfaanbiedingen', $id);
    $this->db->update('fotoaanbiedingen', $insertfoto);
}

我的控制器如下所示:

function editaanbieding()
{
    $data = array(
        'Aanbieding' => $this->input->post('aanbiedingnaam'),
        'Tekst' => $this->input->post('aanbiedingomschrijving'),
        'Prijs' => $this->input->post('aanbiedingprijs'),
        'Conditie' => $this->input->post('aanbiedingconditie')
    );
    $config['upload_path'] = './assets/uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '1000';
    $config['max_width']  = '';
    $config['max_height']  = '';
    $config['overwrite'] = TRUE;
    $config['remove_spaces'] = TRUE;
    $config['file_name'] = $this->input->post('aanbiedingfoto');

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload('aanbiedingfoto'))
    {
        $error = array('error' => $this->upload->display_errors());
    }else{
     $image_data = $this->upload->data();
    }
    $this->aanbieding_model->edit_aanbieding($data, $image_data);
    redirect('members/aanbiedingen');
}

但这不起作用。希望这对我正在努力实现的目标有意义。

4

2 回答 2

0

您可以像这样进行单个更新查询,而不是让 codeigniter 完成这项工作。

UPDATE table1,table2,table3 SET table1.col=a,table2.col2=b,table3.col3=c
WHERE table1.col1=x and table2.col2=y and table3.col3=z;

这对于任何数量的表更新都有效。

于 2013-06-20T10:33:34.300 回答
0

Can't you just add a hidden field with the photo id in your view? I always do it like this:

form_input(array('name' => 'idfoto', 'type'=>'hidden', 'id' =>'23'));
于 2013-06-20T08:24:56.917 回答