gpt4 book ai didi

mysql - 在sql中同时更新两个表中的相同id

转载 作者:行者123 更新时间:2023-11-30 00:07:53 28 4
gpt4 key购买 nike

如果我更新它,如何一次更新两个不同表中的 ID 和名称,仅更改一个表中的 ID,而不是在另一个表中更新。当我复制 Controller 和 View 时。这是总代码,任何人都可以帮助我如何同时更新两个表。型号:

function updatecategory($cat_sub_cat_id)    
{

$this->db->trans_start();
$data=array(
'cat_id'=>$this->input->post('cat_id'),
'name'=>$this->input->post('mainc')
);

$this->db->where('cat_id',$cat_sub_cat_id);
$this->db->update('category',$data);

$data=array(
'cat_id'=>$this->input->post('cat_id')
);

$this->db->where('cat_sub_cat_id',$cat_sub_cat_id);
$this->db->update('category_subcategory_association',$data);

$this->db->trans_complete();

}

Controller :

function editcategory()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');
$this->form_validation->set_rules('cat_id','Category Id','required');
$this->form_validation->set_rules('name','Name','required');
if($this->form_validation->run()==FALSE)
{

$data['records']= $this->bulkupload_model->get_category($this->input->post('cat_sub_cat_id'));
$data['mode'] = "edit";
$data['mainpage'] = "category";
$this->load->view('includes/mainpage', $data);
}
else
{
$this->bulkupload_model ->updatecategory($this->input->post('cat_sub_cat_id'));
if(is_array($result)):
$data['records']=$this->bulkupload_model->get_category($this->uri->segment('cat_sub_cat_id'));
$data['errors']=$result;
$data['mainpage']='category';
$data['mode']='edit';
$this->load->view('includes/mainpage',$data);
else:
$this->flash->success('Successfully Updated the record.');
redirect('uploads/index');
endif;

}
}

查看:

<form id="validation" class="form-horizontal" action="<?php echo base_url();?>uploads/editcategory" method="POST">            
<?php echo form_hidden('cat_sub_cat_id',$record->cat_sub_cat_id);?>
<div class="row-form clearfix">
<div class="span3"><label for="cat_id">Category Id</label></div>
<div class="span9"><input class="validate[required]" type="text" id="cat_id" name="cat_id" value="<?php echo $record->cat_id;?>"/></div>

</div>
<div class="row-form clearfix">
<div class="span3"> <label for="name">Category Name</label> </div>
<div class="span9"><input class="validate[required]" type="text" id="name" name="name" value="<?php echo $record->mainc;?>"/></div>
</div>

最佳答案

难道你这里有错字吗?

$this->bulkupload_model ->updatecategory($this->input->post('cat_sub_cat_id'));
//---------------------^

应该看起来像

$this->bulkupload_model->updatecategory($this->input->post('cat_sub_cat_id'));

关于mysql - 在sql中同时更新两个表中的相同id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24361169/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com