Php 如何使用codeIgniter在单个查询中选择和更新列值
我的数据库包含一个表,在这个表中我有一列“赢得”。此列包含一些值,我必须在此列中添加一些金额(已赚) 现在我可以这样做了Php 如何使用codeIgniter在单个查询中选择和更新列值,php,mysql,codeigniter,codeigniter-3,Php,Mysql,Codeigniter,Codeigniter 3,我的数据库包含一个表,在这个表中我有一列“赢得”。此列包含一些值,我必须在此列中添加一些金额(已赚) 现在我可以这样做了 $this->db->select('Earned'); $this->db->where('CustMobile', $LinkMobile); $query_result=$this->db->get('customers'); $result=$query_result-
$this->db->select('Earned');
$this->db->where('CustMobile', $LinkMobile);
$query_result=$this->db->get('customers');
$result=$query_result->row();
$finalAmount=$result->Earned+$Commsion;
$this->db->set('Earned', $finalAmount);
$this->db->where('CustMobile', $LinkMobile);
$this->db->update('customers');
我想知道如何使用单个查询更新此值
我的数据库看起来像这样
我想将这个带圆圈的值1100改为2000
$this->db->query("UPDATE `customers` SET `Earned` = `Earned` + $Commsion WHERE `CustMobile` = $LinkMobile");
解释
owned=owned+$Commsion
==>此部分将获取字段的值并添加新值
示例-如果$Commsion
为1000,而您各自的收入
字段为1100。因此,它将更新为2100
虽然您已接受答案,但我想为其添加活动记录查询:
$this->db->set('Earned', 'Earned +'. $Commsion .'',false);
$this->db->where('CustMobile', $LinkMobile);
$this->db->update('customers');
当您使用查询生成器时,这是一种更干净的方法。