質問

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());

                    $collection->setPageSize(5);
                    $collection->setCurPage(2);
                    $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>

                        </div>

                   </div>
                </a>




            <?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');
ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top