簡體   English   中英

如何用增量值更新列

[英]How to update the column with increment value

我已使用此查詢以選定的數字遞增我的列,例如

$this->db->where('my Condition');
$this->db->update('my Table',array('name'=>'gautam','count'=>'2'));

在這里,我想將count的實際列值加2 但是我無法使用update功能來做到這一點,而且我仍然可以做到

$this->db->update('my Table',array('name'=>'gautam','count'=>'count+2'));

因為我只得到“ 2”的計數,如果我在查詢中添加它,則在查詢中添加'

enter code here

誰能幫我找出解決方案。

$this->db->set('name', 'gautam');
$this->db->set('count', 'count+2',FALSE);
$this->db->where('my Condition');
$this->db->update('my Table');

$this->db->set()

嘗試這個 :

$this->db->where('my Condition');
$this->db->set(array('count' => 'count+2', 'name' => 'gautam'), FALSE);
$this->db->update('my Table');

您可以使用Codeigniter 設置功能以增量設置count的值。 從文檔

set()也將接受可選的第三個參數($ escape),如果設置為FALSE,它將防止數據被轉義。 為了說明不同之處,這里使用了set(),無論是否使用轉義參數。

因此,您可以執行以下操作:

$this->db->where('my Condition');
$this->db->set('count','count+2',FALSE);//SET COUNT WITH COUNT+2
$this->db->set('name','gautam');
$this->db->update('my Table');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM