0

Hello I am a beginner in using Codeigniter. What I want is to update a data in Codeigniter with an OR condition to the ID.

Here is my MySQL query that I want to make happen:

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

I tried something like this:

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

2 Answers2

0

You can use or_where to apply OR condition in CodeIgniter, I've written a possible solution for your question(Reference).

See if it helps you.

$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' */
sauhardnc
  • 1,961
  • 2
  • 6
  • 16
0

You can apply OR. The references https://www.codeigniter.com/userguide3/database/query_builder.html

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 16 '22 at 19:40