簡體   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