I am new to 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). 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.