Pagination Shows Un Expected Results

Hello All

I am new to YII. I am trying to use ajax pagination with YII in my view but i am having probelems

  • It does not laods the required number of records for the first time

  • Upon click on more, it loads the complete record again and more button disappears

I am sharingmy code here for controller model and view

Controller:




public function actionShopStoresByCategory($storecategory, $affusername = NULL) {


        $this->ticker_news = NewsTicker::model()->getTickerNews();

        if (!empty($affusername))

            $this->VarifyUser($affusername);

            $this->layout = "layout_home";

        $model = new Stores();

        $criteria = new CDbCriteria;

        $total = count($model->getAllStoresByCategory($storecategory));

        $pages = new CPagination($total);

        $pages->pageSize = 5;

        $pages->applyLimit($criteria);

        $posts = $model->getAllStoresByCategory($storecategory);

        $data['stores_cat_data'] = $posts;

        $data['store_id'] = $storecategory;

        $data['store_cat_name'] = Storescat::model()->findByPk($storecategory);


        $this->render('allstoresbycategory', array('model' => $model, 'data' => $data,'pages' => $pages,));

    }



Model:




public function getAllStoresByCategory($category_id) {

    $connection = Yii::app()->db;

    if ($category_id == "22") {

    $sql = "SELECT DISTINCT s.title,s.cCommisions_percentage, s.url, s.id, s.logo, s.publisher_id, cp.subid FROM stores s LEFT JOIN crawling_publisher cp ON s.publisher_id=cp.id WHERE 1 ORDER BY s.title ASC";

    }

else {

        $sql = 'SELECT s.title, s.url, s.id, s.logo, s.cCommisions_percentage, s.publisher_id, sc.store_category_id, cp.subid from stores s

            LEFT JOIN store_categories sc

            ON s.id=sc.store_id

            LEFT JOIN crawling_publisher cp

            ON s.publisher_id=cp.id

            where sc.store_category_id = \'' . $category_id . '\'

                                                            ORDER BY s.title ASC';

    }

    $command = $connection->createCommand($sql);


    $data = $command->queryAll();


    if ($data) {

        return $data;

    } else {

        return false;

    }

}



View:




<?php

 if ($data['store_id'] != 22) {

 ?>

 <div class="featuredcompaniesWrapp">

 <h1>Shop <?php echo $data['store_cat_name']->attributes['title']; ?> by Stores</h1>

 <!--featuredcompaniesRow-->

 <div class="featuredcompaniesRow" id="posts">

 <?php

 if ($data['stores_cat_data']) {

 foreach ($data['stores_cat_data'] as $store_cat) {

 $store_url = $store_cat['url'];

 $separator = (parse_url($store_url, PHP_URL_QUERY) == NULL) ? '?' : '&';

 $store_url = $store_url . $separator . substr($store_cat['subid'], 1);

 $store_url = str_replace("{subid}", $this->current_subid, $store_url);

 ?>         

 <!--featuredcompaniesPost-->

 <div class="featuredcompaniesPost"> <a href="<?php echo $this->base_url ?>/pages/<?php echo $store_cat['id'] ?>" target="_blank"><img src="<?php echo $this->theme_baseurl ?>/images/stores/<?php echo $store_cat['logo'] ?>" alt="<?php echo $store_cat['title'] ?>" /></a>

 <h3>&nbsp;<!--<a href="<?php echo $this->prep_url($store_url) ?>" target="_blank"><?php echo $store_cat['title'] ?></a> --></h3>

 </div>

 <!--featuredcompaniesPost-->

  <?php

  }

  }

                    ?>


                </div>

              <?php $this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array(

'contentSelector' => '#posts',

'itemSelector' => 'div.featuredcompaniesRow',

'loadingText' => 'Loading...',

'donetext' => 'This is the end... my only friend, the end',

'pages' => $pages,

)); ?>

                <!--featuredcompaniesRow-->

            </div>

            <?php

        }

        ?>



Thanks in advance