【问题标题】:Codeigniter updating data with OR condition in IDCodeigniter 用 ID 中的 OR 条件更新数据
【发布时间】:2020-05-26 04:30:58
【问题描述】:

您好,我是使用 Codeigniter 的初学者。我想要的是用 ID 的 OR 条件更新 Codeigniter 中的数据。

这是我想要实现的 MySQL 查询:

Update message_received SET is_read = 1 WHERE msg_id = 3 OR parent_id = 3

我尝试过这样的事情:

$this->query->update_array('message_received', array('msg_id' => $_POST['read_my_message'],'parent_id' => $_POST['read_my_message']) , array('is_read'=>1));

【问题讨论】:

    标签: codeigniter codeigniter-query-builder


    【解决方案1】:

    您可以使用or_whereCodeIgniter 中应用OR 条件,我已经为您的问题编写了一个可能的解决方案(Reference)。

    看看它是否对您有帮助。

    $msg = $this->input->post('read_my_message'); // get the post data
    
    $this->db->set('is_read', 1); // set the value of column
    $this->db->where('msg_id', $msg); // first condition
    $this->db->or_where('parent_id', $msg); // second contion
    $this->db->update('message_received'); // table name
    
    // Produces:
    /* UPDATE `message_received` SET `is_read` = 1 WHERE `msg_id` = '$msg' OR `parent_id` = '$msg' */
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 2021-08-15
      • 2019-09-15
      • 2019-06-24
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多