baig772 19 Web Application Architect

Problem I need an jax pagination in YII, The problems are

  • its not showing the required results for the first time. ie. it is showing the complete result
  • When clicked on more, it again shows the complete result below that section as it is

What Needed

  • i need to show, say 5 records for the first time
  • load the remaining results (5 rows) once clicked on more and so on
    My Wordkout

ControllerAction

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,));
    }

Moedl

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 for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.