dougu5950 2016-06-08 09:21
浏览 96
已采纳

更新两个表Codeigniter

I'm trying to update 2 tables tbl_loanledger and tbl_journal at the same time. Both tables have the same columns such as modified_by, date_modified and deleted.

When I try to run this I enter code here I'm getting an error :

Error Number: 1052

Column 'modified_by' in field list is ambiguous

UPDATE `loan_ledger` as a, journal as b SET `modified_by` = '1', `date_modified` = '2016-06-08', `deleted` = 1 WHERE `a`.`id` = '823' AND `b`.`id` = '823'

Filename: C:\xampp\htdocs\system\system\database\DB_driver.php

Line Number: 331

Is this the right way on how to update 2 tables in codeigniter?

Model

public function delete($id){

  $data = array(
        'modified_by' => $this->ion_auth->user()->row()->id,
        'date_modified' => date("Y-m-d"),
        'deleted' => 1
      );

    $this->db->set($data);
    $this->db->where('a.id', $id);
    $this->db->where('b.id', $id);
    $this->db->update('loan_ledger as a, journal as b');

}

But if I am just updating single table, it is working, here is a the code:

public function delete($id){

  $data = array(
        'modified_by' => $this->ion_auth->user()->row()->id,
        'date_modified' => date("Y-m-d"),
        'deleted' => 1
      );
    $this->db->where('id', $id);
    $this->db->update(tbl_loanledger, $data);

}
  • 写回答

3条回答 默认 最新

  • dongshuo2752 2016-06-08 10:04
    关注

    No Use of join just write two seperate update query as

     // first 
        $this->db->set('a.modified_by', $this->ion_auth->user()->row()->id);
        $this->db->set('a.date_modified', date("Y-m-d"));
        $this->db->set('a.deleted', 1);
        $this->db->where('a.id',  $id);
        $this->db->update('loan_ledger as a');
        // second
        $this->db->set('b.modified_by', $this->ion_auth->user()->row()->id);
        $this->db->set('b.date_modified', date("Y-m-d"));
        $this->db->set('b.deleted', 1);
        $this->db->where('b.id',  $id);
        $this->db->update('journal as b');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义