Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用codeIgniter在单个查询中选择和更新列值_Php_Mysql_Codeigniter_Codeigniter 3 - Fatal编程技术网

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');

当您使用查询生成器时,这是一种更干净的方法。