I want to load data from a table using collection and I need the result to be in the ascending order of the 'sort_order' column which is an integer value.admin form

The above pic shows the columns in admin form.

Database Table

The above pic is of the database table.

This is the code which I used to retrieve the collection.

                    $collection = Mage::getModel('hm_faq/object')->getCollection()->addFieldToFilter('category_id',$category->getId());

                    $size = $collection->getSize();
                    $cnt = count($collection);
                    foreach ($collection as $button) {
                        $i = $i+1;

                <a id="<?php echo $button->getUrlId(); ?>" href="<?php echo $button->getUrlLink(); ?>" >
                    <div  class="faq-white-button">

                        <div class="faq-inner">

                                <h3 class="faq-button-label"><?php echo $button->getUrlLabel(); ?></h3><span class="faq-icon">></span>



            <?php echo '<br>';} ?>

How can i arrange the result in the ascending order of the sort_order?


Try with this:

$collection->setOrder('sort_order', 'ASC');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.