Codeigniter active record update statement with a join

后端 未结 2 1037
夕颜
夕颜 2020-12-30 12:24

This is the query that i\'m trying to achieve via active record:

UPDATE `Customer_donations` cd 
join Invoices i on i.cd_id = cd.cd_id 
set cd.amount = \'4\'         


        
2条回答
  •  独厮守ぢ
    2020-12-30 12:45

    How about the solution below? A bit ugly but it achieved what you expected in your question.

    $invoiceId = 13;
    $amount = 4;
    $data = array('cd.amount'=>$amount, 'cd.amount_verified'=>'1');
    
    $this->db->where('i.invoice_id', $invoiceId);
    
    $this->db->update('Customer_donations cd join Invoices i on i.cd_id = cd.cd_id', $data);
    

提交回复
热议问题