Code Scrolling

I am using the scrollpagination jquery plugin in codeigniter. I am facing the problem that my cycle does not end and alos does not give an exact result.

this is my html code

<div id="main">
    <div id='friend_display'>
    <?php if($list->num_rows() > 0  ){
            foreach($list->result() as $show)
            {   ?>

    <div class="image-box" style="margin-left:30px" id='image-holder' >

        <div class="photo-cover">
            <a href="<?=base_url()?>uploads/user_images/<?php echo $show->user_image;?>" class="big-image"><img width="160px" height="117px" src="<?=base_url()?>uploads/user_images/friends/<?php echo $show->user_image;?>" alt="" /></a>
        </div>

        <p class="photo-name"><b><?php echo $show->user_name;?></b></p>


    </div>
    <?php } } else { echo '<div align="center" style="color:#FF0000; font-size:17px; font-weight:bold">You have no Friends yet</div>';}?>

    <div class="cl">&nbsp;</div>
</div></div>

this is a script

  <script type="text/javascript">
  var page_num = 1; 
   $(function(){
$('#friend_display').scrollPagination({
    'contentPage': '<?=base_url()?>friends/load_more', // the url you are fetching the results
    '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
    'scrollTarget': $(window), // who gonna scroll? in this example, the full window
    'heightOffset': 10, // it gonna request when scroll is 10 pixels before the page ends
    'beforeLoad': function(){ // before load function, you can display a preloader div
        $('#loading1').fadeIn();    
    },
    'afterLoad': function(elementsLoaded){ // after loading content, you can use this function to animate your new elements
         $('#loading1').fadeOut();
         var i = 0;
         $(elementsLoaded).fadeInWithDelay();
         page_num:$('.image-box').size();
    }
});

// code for fade in element by element
$.fn.fadeInWithDelay = function(){
    var delay = 0;
    return this.each(function(){
        $(this).delay(delay).animate({opacity:1}, 200);
        delay += 100;
    });
};

 });
</script>   

and this is my php function

  function load_more() 
{
    $offset =   $this->input->post('page_num');
    $list       =   $this->friends_model->show_friends($offset);
    if($list->num_rows()>0)
    {
        foreach($list->result() as $show)
        {?>

            <div class="image-box" style="margin-left:30px" id='image-holder'>
            <div class="photo-cover">
            <a href="<?=base_url()?>uploads/user_images/<?php echo $show->user_image;?>" class="big-image"><img width="160px" height="117px" src="<?=base_url()?>uploads/user_images/friends/<?php echo $show->user_image;?>" alt="" /></a>
            </div>

        <p class="photo-name"><b><?php echo $show->user_name;?></b></p>

    </div>
    <?php } ?>
    <div class="cl">&nbsp;</div>
    <?php
    } 
    else 
    {  
        //echo(333); 
    }
}

in db i jst shoing main query $ This-> db-> limit (12, $ offset); can someone tell me what i am missing?

Open the link to the full wathch code. Scroll pagination

+5
source share
4 answers

Here I solve this problem in my own way, you can try it. In your script, delete this line

'contentData': {page_num:$('.image-box').size()},

 'childClass' : '.image-box',

scrollpagination.js data: opts.contentData, data: {page_num : $(obj).children(opts.childClass).size()},. 'contentData' : {}, 'childClass' : '.datalist',.

function display_friends() exit; echo '<input type="hidden" id="nodata" value="1" />';. script :

$(function(){

    $('#nomoreresult').hide();
    $('#loading1').hide();
    $('#friend_display').scrollPagination({

    'contentPage': 'Your_Url', // the url you are fetching the results
     // these are the variables you can pass to the request, for example: children().size() to know which page you are
    'childClass' : '.image-box',
    'scrollTarget': $(window), // who gonna scroll? in this example, the full window
    'heightOffset': 10, // it gonna request when scroll is 10 pixels before the page ends
    'beforeLoad': function(){ // before load function, you can display a preloader div
        $('#loading1').show().fadeIn();
    },
    'afterLoad': function(elementsLoaded){
     // after loading content, you can use this function to animate your new elements
        $('#loading1').hide().fadeOut();
        $(elementsLoaded).fadeInWithDelay();

        if($('#nodata').val() == '1'){
            $('#friend_display').stopScrollPagination();
            $('#loading1').hide();
            $('#nomoreresult').show().fadeIn();

        }

    }
});

// code for fade in element by element
$.fn.fadeInWithDelay = function(){
    var delay = 0;
    return this.each(function(){
        $(this).delay(delay).animate({opacity:1}, 200);
        delay += 1000;
    });
};
+1

, , , . (, , , POST ['page_num'])

$offset =   $this->input->post('page_num');

, , . , 12 "", 12 * page_number

$this->db->limit(12,$offset*12);

, :

limit(12,[0,1,2,...]) // items 1-12, 2-13, 3-14 etc...

limit(12,[0,12,24....] //items 1-12, 13-24, 25-32 etc...
+2

jQuery.noConflict()?

  <script type="text/javascript">
  var page_num = 1; 
  jQuery.noConflict();
   $(function(){...

Edit2: , . http://pastebin.com/MC1KZm8y

:

$offset =   $this->input->post('page_num');
$list       =   $this->friends_model->find($offset);

:

$page_line = 6; //for example
$page_num = $this->input->post('page_num');
$offset   = ($page_num -1) * $page_line;
$list       =   $this->friends_model->find($offset);
0

Add this missing code inside the code afterLoad:function(){.., it should also stop your pagination cycle, do not forget to add exactly the same identifier that you entered forscrollpagination id <div id='friend_display'>

if ($('#friend_display').children().size() > 100){ //set the condition to where to stop
// if more than 100 results already loaded, then stop pagination (only for testing)
    $('#nomoreresults').fadeIn(); //if you want to show message like "No more result!" use this
    $('#friend_display').stopScrollPagination();// this is the most important function call
}

inside .scrollPagination({..change 'contentPage': '<?php echo base_url();?>controller/action'inside this action(){ $this->load->view('that_you_want_to_display');means that your display_friends () method should only contain a view file that you need to load and analyze, as well as the data you want to display, and inside this view, echo your data using foreach

0
source

All Articles