How to query in Codeigniter with limit and without limit for pagination?

$this->db->start_cache();

$this->db->select("p.*");
$this->db->from('product p');

$this->db->where("p.cat_id", "12");
$this->db->group_by("p.id");

$this->db->stop_cache();

# Get total number of products
$total_product = $this->db->count_all_results();

# show only 5 products
$this->db->limit(5, 0);

$query = $this->db->get();
$this->db->flush_cache();

        
$result 	  = $query->result_array();
$result_count = $query->num_rows();

Leave a Comment