Some of the Best ways to limit your collection size are:
setPageSize()
This function will limit the number of results that are returned – basically using a LIMIT X mysqli query. For example:
$collection->setPageSize(10);
echo $collection->count(); // will echo 10
setPage()
setPage()
is similar to using setPageSize but you can add two parameters – just like you would with mysqli LIMIT 10,5 for example. The first parameter being the start from point – the next being how many you wish to bring back:
$collection->setPage(0,20); // will bring back the first 20 products
$collection->setPage(10,5); // will bring back 5 products after the 10th product
getSelect()->limit()
This function allows you to add your own limit to the select query – its basically the same as entering LIMIT X. For example:
$collection->getSelect()->limit(20); // will bring back our first 20 results
A handy hint to see what these limits are doing to your mysqli query is to echo out your mysqli query in the code. To do this you can simply perform the following after you’ve tweaked your $collection object:
echo $collection->getSelect()
For Second $limit
&& $offset
Example
You imagen you run one query like :
$sql = "SELECT * FROM Orders LIMIT 30";
When the SQL query above is run, it will return the first 30 records
What if we want to select records 16 - 25 (inclusive)?
Mysqli also provides a way to handle this: by using OFFSET
.
The SQL query below says "return only 10 records, start on record 16 (OFFSET 15)":
$sql = "SELECT * FROM Orders LIMIT 10 OFFSET 15";
In short in your collection add $limit && $offset.And above I explain how work $limit && $offset .
I Hope you are understand and solve your issue.
THANKS.