gpt4 book ai didi

php - Codeigniter 滚动分页

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:41:47 24 4
gpt4 key购买 nike

我在 codeigniter 中使用 jquery 插件 scrollpagination 我面临的问题是我的循环没有终止并且也没有给出准确的结果。

这是我的html代码

<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>

这是脚本

  <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>

这是我的 php 函数

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

db 我只是支持主查询 $this->db->limit(12,$offset);有人可以告诉我我错过了什么吗?

打开此链接可观看完整代码。 Scroll Pagination

最佳答案

我相信您获取偏移量的方式不正确。 (以为我不确定,因为我不知道你的 POST['page_num'] 里有什么)

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

看起来你获取的是页码,但是 limit 函数中的偏移量应该是必须跳过多少行。因此,如果每个“刻度”显示 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...

关于php - Codeigniter 滚动分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15027416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com