繁体   English   中英

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

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

我是Codeigniter的新手。 我有一张桌子,上面有三个字段

id (primary key / auto incremented)
groupId
text

我的问题是,当我通过表单插入多行时,整个行组应具有相同的groupId(在最后添加的groupId中增加1)。 我不知道该怎么做。 请帮忙。

您应该真正保留您的代码或其难以响应的代码,但是我希望您正在寻找类似...

$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