How to use get_where in codeigniter

0
CodeIgniter- scripts.guru

CodeIgniter is a framework based on MVC principles. As a result, you would usually separate application logic, data abstraction and “output” into their respective areas for CodeIgniter use. In this case: controllers, models and views.

to get data using a where condition in Codeigniter you need to use below syntax.

$this->db->get_where() allows you to create a SQL select query having the WHERE Clause.

$table_name – Your table name.

$where_array – Array which generates the condition.

$limit – no of records to be loaded.

$offset – the start of limit.

Code

$query = $this->db->get_where($table_name,$where_array, $limit, $offset);

Example

$role_id = 2;
$role = $this->db->get_where('user_roles', array('id' => $role_id))->row()->name;