Advertisement
Guest User

Codeigniter Scroll Pagination

a guest
Mar 14th, 2013
1,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.70 KB | None | 0 0
  1. This is my view file
  2. friends_find_view.php
  3.  
  4.  
  5. <link rel="stylesheet" href="<?=base_url()?>css/friends.css" type="text/css" media="all" />
  6.    
  7.     <div class="shell" >
  8.     <!-- main -->
  9.     <div id="main" style="width:760px">
  10.         <div id='friend_display'>
  11.         <?php if($list->num_rows() > 0  ){
  12.      foreach($list->result() as $show){ ?>
  13.         <!-- image box -->
  14.         <div class="image-box" style="margin-left:30px" id='image-holder' >
  15.            
  16.             <div class="photo-cover">
  17.                 <img width="160px" height="117px" src="<?=base_url()?>uploads/user_images/friends/<?php echo $show->user_image;?>" alt="" />
  18.             </div>
  19.    
  20.             <p class="photo-name"><b><?php echo $show->user_name;?></b></p>
  21.             <!-- end photo name -->
  22.  
  23.         </div>
  24.         <?php } } else { echo '<div align="center" style="color:#FF0000; font-size:17px; font-weight:bold">You have no Friends yet</div>';}?>
  25.         <!-- end image-box -->
  26.         <div class="cl">&nbsp;</div>
  27.     </div>
  28.     <!-- end main -->
  29.     </div>
  30.  
  31. </div>
  32.  
  33.    
  34.      <div class="loading1" id="loading1">Wait a moment... it's loading!</div>
  35.     <div class="loading1" id="nomoreresults">Sorry, no more results....!</div>
  36.    
  37.         </div>
  38.        
  39.  
  40. <script src="<?=base_url()?>js/libs/jquery-1.7.2.min.js"></script>        
  41. <script type="text/javascript">
  42. var page_num = 1;
  43. $(function(){
  44.     $('#friend_display').scrollPagination({
  45.         'contentPage': '<?=base_url()?>friends/display_friends', // the url you are fetching the results
  46.         'contentData': {page_num:$('.image-box').size()}, // these are the variables you can pass to the request, for example: children().size() to know which page you are
  47.         'scrollTarget': $(window), // who gonna scroll? in this example, the full window
  48.         'heightOffset': 10, // it gonna request when scroll is 10 pixels before the page ends
  49.         'beforeLoad': function(){ // before load function, you can display a preloader div
  50.             $('#loading1').fadeIn();   
  51.         },
  52.         'afterLoad': function(elementsLoaded){ // after loading content, you can use this function to animate your new elements
  53.              $('#loading1').fadeOut();
  54.              $(elementsLoaded).fadeInWithDelay();
  55.              page_num:$('.image-box').size();
  56.         }
  57.     });
  58.    
  59.     // code for fade in element by element
  60.     $.fn.fadeInWithDelay = function(){
  61.         var delay = 0;
  62.         return this.each(function(){
  63.             $(this).delay(delay).animate({opacity:1}, 200);
  64.             delay += 100;
  65.         });
  66.     };
  67. });
  68.    
  69. </script>
  70.  
  71.  
  72. /*          End View  */
  73.  
  74. This is controller
  75. Friends.php
  76.  
  77.  
  78. <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  79. class Friends extends CI_Controller {
  80.  
  81.     function __construct()
  82.     {
  83.         parent::__construct();
  84.         $this->load->model('friends_model');
  85.     }
  86.  
  87.    
  88.     function find_friends($offset=0)
  89.     {
  90.         $friend['list']     =   $this->friends_model->find($offset);
  91.         $this->load->view('friends_find_view',$friend);
  92.     }
  93.    
  94.    
  95.     function display_friends()
  96.     {
  97.         $offset =   $this->input->post('page_num');
  98.        
  99.         $find   =   $this->friends_model->find($offset);
  100.        
  101.         if($find->num_rows() > 0    )
  102.         {
  103.             foreach($find->result() as $show)
  104.             {   ?>
  105.        
  106.         <div class="image-box" style="margin-left:30px" id='image-holder' >
  107.             <div class="photo-cover">
  108.                 <img width="160px" height="117px" src="<?=base_url()?>uploads/user_images/friends/<?php echo $show->user_image;?>" alt="" />
  109.             </div>
  110.    
  111.             <p class="photo-name"><b><?php echo $show->user_name;?></b></p>
  112.             <!-- end photo name -->
  113.  
  114.         </div>
  115.         <?php } } else { exit; }?>
  116.         <!-- end image-box -->
  117.         <div class="cl">&nbsp;</div>
  118.         <?php      
  119.     }
  120. }  
  121.  
  122. /* End Controller  */
  123.  
  124. This is code for my query to fetch record from model
  125.  
  126.     function find($offset)
  127.     {
  128.         $this->db->select('*');
  129.         $this->db->from('users');
  130.        
  131.         $this->db->limit(6,$offset);
  132.         $result = $this->db->get();
  133.         return $result;    
  134.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement