codeigniter select query with multiple clauses
In this article, we will explain how to use a select query with multiple clauses in Codeigniter. The Codeigniter provides Active Record class and that class through we can get data from the database using a select query.
CodeIgniter Select Query Example
1 2 3 4 | $this->db->select("*"); $this->db->from("users"); $objQuery = $this->db->get(); $data = $objQuery->result_array(); |
Codeigniter select query with get where clause
1 2 3 4 5 | $this->db->select("*"); $this->db->from("users"); $this->db->where('id',2); $objQuery = $this->db->get(); $data = $objQuery->result_array(); |
Codeigniter Select Query with Multiple Where Clause
1 2 3 4 5 6 | $this->db->select("*"); $this->db->from("users"); $this->db->where('id',1); $this->db->where('first_name','test'); $objQuery = $this->db->get(); $data = $objQuery->result_array(); |
Codeigniter select query with Or Where clause
1 2 3 4 5 | $this->db->select("*"); $this->db->from("users"); $this->db->or_where('first_name', 'test'); $objQuery = $this->db->get(); $data = $objQuery->result_array(); |
Codeigniter select query with Where In clause
1 2 3 4 5 | $this->db->select("*"); $this->db->from("users"); $this->db->where_in('id',array(1,2)); $objQuery = $this->db->get(); $data = $objQuery->result_array(); |
Codeigniter select query with Where Not In clause
1 2 3 4 5 | $this->db->select("*"); $this->db->from("users"); $this->db->where_not_in('id',array(1,2)); $objQuery = $this->db->get(); $data = $objQuery->result_array(); |
Codeigniter select query with Like clause
1 2 3 4 5 | $this->db->select("*"); $this->db->from("users"); $this->db->like('first_name', 's', after); $objQuery = $this->db->get(); $data = $objQuery->result_array(); |
Codeigniter select query with Limit clause
1 2 3 4 5 | $this->db->select("*"); $this->db->from("users"); $this->db->limit(5, 10); $objQuery = $this->db->get(); $data = $objQuery->result_array(); |
Codeigniter select query with Join clause
You can refer to this URL for Codeigniter select query with join clause.
Codeigniter select query with Order By clause
1 2 3 4 5 | $this->db->select("*"); $this->db->from("users"); $this->db->order_by('id', 'desc'); $objQuery = $this->db->get(); $data = $objQuery->result_array(); |
Please follow and like us: