我是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);