问题
如何在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');
}
但这不起作用。希望我尝试实现的目标是有意义的。
答案 0 :(得分:0)
您不能只在视图中添加带照片ID的隐藏字段吗?我总是这样做:
form_input(array('name' => 'idfoto', 'type'=>'hidden', 'id' =>'23'));
答案 1 :(得分: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;
这对任意数量的表更新都有效。