codeigniter 3 or where in

To perform a WHERE IN query in CodeIgniter 3, you can follow these steps:

  1. Load the database library:

This will load the default database configuration and initialize the database connection.

  1. Build the WHERE IN condition:
$ids = array(1, 2, 3, 4); // Example array of IDs
$this->db->where_in('id', $ids);

This code defines an array of IDs and uses the where_in() method to specify the column name and the array of values to match.

  1. Execute the query:
$query = $this->db->get('table_name');

This code uses the get() method of the database library to retrieve the records from the specified table. Replace 'table_name' with the actual name of your table.

  1. Process the results:
foreach ($query->result() as $row) {
    // Process each row of data here

This code iterates over the result set and allows you to process each row of data. You can access the columns of each row using object notation, like $row->column_name.

That's it! You have successfully executed a WHERE IN query in CodeIgniter 3. Remember to replace 'table_name' with your actual table name, and adjust the column name and array of values in the where_in() method to match your specific requirements.