简体   繁体   English

使用codeigniter将数据库中添加的行的值更新1

[英]Update the value of added rows in database by 1 using codeigniter

I am new to codeigniter. 我是Codeigniter的新手。 I have a table with three fields 我有一张桌子,上面有三个字段

id (primary key / auto incremented)
groupId
text

my problem is when i insert multiple rows through form the whole group of rows should get same groupId (incremented by 1 in last added groupId). 我的问题是,当我通过表单插入多行时,整个行组应具有相同的groupId(在最后添加的groupId中增加1)。 I dont know how to do it. 我不知道该怎么做。 Please help. 请帮忙。

You should really leave your code or its hard to respond but I expect you are looking for something like... 您应该真正保留您的代码或其难以响应的代码,但是我希望您正在寻找类似...

$this->db->select_max('group_id','max_group_id');
$query = $this->db->get('whatever_your_table_is_called');

//this increments the highest group id by 1
$next_group_id = $query->result_array()[0]['max_group_id']+1;

//do your loop probably
foreach($group_of_users as $user){
   $data[]=array('group_id'=>$next_group_id,'text'=>$user['text_value'])
}

$this->db->insert_batch('whatever_your_table_is_called', $data); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM