Set limit on Magento Collections


<?php
$limit = 5;
$starting_from = 2;
$product_collection = Mage::getModel('catalog/product')->getCollection()->setOrder('name', 'asc'); //getting the product collection, results are ordered by product name
$product_collection->getSelect()->limit($limit,$starting_from);   //where $limit will be the number of results we want, $starting_from will be the index of the result set to be considered as starting point (note 0 is the index of first row)
//this will ouptput 5 records starting from 3rd record
foreach($product_collection as $_product)
{
    echo $_product->getName().'<br/>';
}
?>

Comments

Post a Comment

Popular posts from this blog

Sort Products by popularity count in Magento

Safe name of a file by php

Get width height of image using Varien-image class in Magento