Codeigniter active record update statement with a join

后端 未结 2 1044
夕颜
夕颜 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:51

    Even cleaner, since update accepts a third "where" array parameter:

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

提交回复
热议问题