Codeigniter get_where example

Codeigniter get_where example : This is basically used to get data based on where condition. Let us create a simple example to understand how “where” clause works in Codeigniter.

Codeigniter get_where Condition

Codigniter $this->db->get_where() allows you to create a sql slect query having the WHERE Clause.

$query = $this->db->get_where($table_name,$where_array, $limit, $offset);
$table_name – Your table name.
$where_array – Array which generates the condition.
$limit – no of records to be loaded.
$offset – start of limit.

Codeigniter get_where With Multiple Conditions example

You can use get_where in codeiniter to add one or multiple conditions. Here in this examplewe have added two conditions in where clause.

$where_array = array(
               'email'=>'test@gmail.com',
               'status'=>'1'
              );
$table_name = "users";
$limit = 10;
$offset = 0;
$query = $this->db->get_where($table_name,$where_array, $limit, $offset);

If you run the above example it will generate the following query:


SELECT * from users where email='test@gmail.com' AND status ='1' limit 0, 10;

On the same way you can add multiple conditions.


Advertisements

Add Comment

📖 Read More