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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵