简体   繁体   中英

how to increase database column value by one?

So basically I have a database, and on each update I need to increase it's countValue by 1.

How would I do it with codeIgniter?

Here are some code -

            $data = array(
                "up" => date('Y-m-d H:i:s'),
                "viewCount" => viewCount+1
            );              
            $this->db->where('url', $url);
            $this->db->update('table', $data);  

How would I do that? I know that I must change viewCount+1 to something else for it to work. Hope I explained the question well enough. With default SQL query I would be able to do it just with SET count = count + 1 , but here it's not working.

按照此线程 ,您可以执行以下操作:

$this->db->set('ViewCount','ViewCount + 1',false);

Try as below using set function

   $this->db->where('url', $url);
   $this->db->set('viewCount', 'viewCount+1', FALSE);
   $this->db->set('up', date('Y-m-d H:i:s'));
   $this->db->update('table'); 

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM