How to use get_where in codeigniter php

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.

I strongly advise you to read through the given User Guide to become acquainted with CodeIgniter; it should guide you through the majority of the processes. Table of Contents is a good place to start (top right).

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;

Leave a Reply

Your email address will not be published. Required fields are marked *