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.
$this->db->select("*");
$this->db->from("users");
$objQuery = $this->db->get();
$data = $objQuery->result_array();
$this->db->select("*");
$this->db->from("users");
$this->db->where('id',2);
$objQuery = $this->db->get();
$data = $objQuery->result_array();
$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();
$this->db->select("*");
$this->db->from("users");
$this->db->or_where('first_name', 'test');
$objQuery = $this->db->get();
$data = $objQuery->result_array();
$this->db->select("*");
$this->db->from("users");
$this->db->where_in('id',array(1,2));
$objQuery = $this->db->get();
$data = $objQuery->result_array();
$this->db->select("*");
$this->db->from("users");
$this->db->where_not_in('id',array(1,2));
$objQuery = $this->db->get();
$data = $objQuery->result_array();
$this->db->select("*");
$this->db->from("users");
$this->db->like('first_name', 's', after);
$objQuery = $this->db->get();
$data = $objQuery->result_array();
$this->db->select("*");
$this->db->from("users");
$this->db->limit(5, 10);
$objQuery = $this->db->get();
$data = $objQuery->result_array();
You can refer to this URL for Codeigniter select query with join clause.
$this->db->select("*");
$this->db->from("users");
$this->db->order_by('id', 'desc');
$objQuery = $this->db->get();
$data = $objQuery->result_array();