Update Query in Codeigniter Using Multiple Where Condition

CodeIgniter Update Query with Multiple Where Conditions

To perform an update query with multiple where conditions in CodeIgniter, you can use the update() method provided by the framework's database class. Here are the steps to achieve this:

  1. Load the Database Library: Before you can use the database functionality in CodeIgniter, you need to load the database library. This can be done in the controller where you want to use the update query, or you can autoload it in the config/autoload.php file.

php $this->load->database();

  1. Build the Update Query: Use the set() method to specify the columns and their new values that you want to update in the database table. You can chain multiple set() methods to update multiple columns.

php $this->db->set('column1', 'value1'); $this->db->set('column2', 'value2');

  1. Add the Where Conditions: To specify the conditions for the update query, use the where() method. You can chain multiple where() methods to add multiple conditions. Each where() method takes two parameters: the column name and the condition value.

php $this->db->where('column3', 'value3'); $this->db->where('column4', 'value4');

  1. Execute the Update Query: Finally, to execute the update query, call the update() method on the database object. Pass the table name as the first parameter.

php $this->db->update('table_name');

The update query will be executed and the specified columns in the table will be updated based on the provided where conditions.

And that's how you can perform an update query in CodeIgniter with multiple where conditions!