Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无限滚动的SQL限制问题_Php_Mysql_Sql - Fatal编程技术网

Php 无限滚动的SQL限制问题

Php 无限滚动的SQL限制问题,php,mysql,sql,Php,Mysql,Sql,我有一个在图库中加载图像的功能。 在整个站点中,它加载最后20个图像,然后当用户向下滚动时,它加载另外20个图像,并使用无限滚动代码 然而,有一页说这不起作用,我不明白为什么不起作用 我已将问题代码缩小为: function getEachBoardPins($id,$limit=false) { $sql = "SELECT * FROM pins

我有一个在图库中加载图像的功能。 在整个站点中,它加载最后20个图像,然后当用户向下滚动时,它加载另外20个图像,并使用无限滚动代码

然而,有一页说这不起作用,我不明白为什么不起作用

我已将问题代码缩小为:

function getEachBoardPins($id,$limit=false)
{

    $sql    = "SELECT 
                    *
                FROM
                    pins
                WHERE
                    board_id = $id
                ORDER BY time DESC";
    if($limit)
        $sql .=" LIMIT $limit" ;
    $query  = $this->db->query($sql);
    return $query->result();
}
这将加载库中的每个图像。一些画廊有超过1000张图片,因此需要很长时间才能载入

通过将第一行中的“$limit=false”值更改为true,仅渲染最后上载的图像

有人能帮我或给我指出一个好的方向,让我解决它吗

谢谢

编辑:

无限滚动代码:

$(function(){

    // alert($('.pin_item').length);

    var $alpha = $('#alpha');
    $alpha.imagesLoaded( function(){
        $alpha.masonry({
            itemSelector: '.pin_item',
            isFitWidth: true,
            isAnimatedFromBottom: true

            //isAnimated: true
        });
    });
    $alpha.infinitescroll({
        navSelector  : '#page-nav',    // selector for the paged navigation
        nextSelector : '#page-nav a',  // selector for the NEXT link (to page 2)
        itemSelector : '.pin_item',     // selector for all items you'll retrieve

        loading: {

            finishedMsg: 'No more pages to load.',
            img: '<?php echo site_url(); ?>/application/assets/images/ajax_loader_blue.gif'
        }
    },

    // trigger Masonry as a callback
    function( newElements ) {
        // hide new items while they are loading
        var $newElems = $( newElements ).css({ opacity: 0 });
        // ensure that images load before adding to masonry layout
        $newElems.imagesLoaded(function(){
            // show elems now they're ready
            $newElems.animate({ opacity: 1 });
            $alpha.masonry( 'appended', $newElems, true );
            $("a.act_uncomment").hide();
            $(".enter_comm").hide();
            //Examples of how to assign the ColorBox event to elements
            $(".group1").colorbox({rel:'group1'});
            $(".group2").colorbox({rel:'group2', transition:"fade"});
            $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
            $(".group4").colorbox({rel:'group4', slideshow:true});
            $(".ajax").colorbox({scrolling:false,transition:"elastic"});
            $(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344});
            $(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
            $(".inline").colorbox({inline:true, width:"50%"});
            $(".callbacks").colorbox({
                onOpen:function(){ alert('onOpen: colorbox is about to open'); },
                onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
                onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
                onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
                onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
            });

            //Example of preserving a JavaScript event for inline calls.
            $("#click").click(function(){
                $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
                return false;
            });

        });
    }
);

});
$(函数(){
//警报($('.pin_item')。长度);
变量$alpha=$(“#alpha”);
$alpha.imagesLoaded(函数(){
$alpha.砖石({
项目选择器:'.pin_项目',
是的,
isAnimatedFromBottom:对
//我说:是的
});
});
$alpha.infinites卷({
导航选择器:'#页面导航',//页面导航的选择器
下一个选择器:“#页面导航a”,//下一个链接(到第2页)的选择器
itemSelector:'.pin_item',//将检索的所有项目的选择器
装载:{
FinishedMg:“没有更多页面要加载。”,
img:“/application/assets/images/ajax\u loader\u blue.gif”
}
},
//触发器作为回调
函数(新元素){
//在加载新项目时隐藏它们
var$newElems=$(newElements).css({opacity:0});
//确保在添加到砌体布局之前加载图像
$newElems.imagesLoaded(函数(){
//显示元素现在他们准备好了
$newElems.animate({opacity:1});
$alpha.砖石('added',$newElems,true);
$(“a.act_uncomment”).hide();
$(“.enter_comm”).hide();
//如何将ColorBox事件指定给元素的示例
$(“.group1”).colorbox({rel:'group1'});
$(“.group2”).colorbox({rel:'group2',transition:'fade'});
$(“.group3”).colorbox({rel:'group3',transition:'none',width:'75%',height:'75%});
$(“.group4”).colorbox({rel:'group4',slideshow:true});
$(“.ajax”).colorbox({滚动:false,转换:“弹性”});
$(“.youtube”).colorbox({iframe:true,innerWidth:425,innerHeight:344});
$(“.iframe”).colorbox({iframe:true,宽度:“80%”,高度:“80%”);
$(“.inline”).colorbox({inline:true,宽度:“50%”);
$(“.callbacks”).colorbox({
onOpen:function(){alert('onOpen:colorbox即将打开');},
onLoad:function(){alert('onLoad:colorbox已开始加载目标内容');},
onComplete:function(){alert('onComplete:colorbox已显示加载的内容');},
onCleanup:function(){alert('onCleanup:colorbox已开始关闭过程');},
onClosed:function(){alert('onClosed:colorbox已完全关闭');}
});
//为内联调用保留JavaScript事件的示例。
$(“#单击”)。单击(函数(){
$('#click').css({“背景色”:“#f00”,“颜色”:“#fff”,“光标”:“继承”});
返回false;
});
});
}
);
});

所有mysql体验限制都应设置为整数,因此最多只能返回这么多结果。尝试在该查询中添加一个数字限制

这样做,无论您传入多少个数字,都只会返回最后一个
$limit
记录数。如果要查询更多图像,则将返回已检索到的所有记录以及其他记录(例如,如果您只是增加该数字)

此外,与其将
$limit
作为布尔/整数传递(混合数据类型不是好的做法),不如将其作为数字传递。例如:

function getEachBoardPins($id, $start=0, $numrows=20)
{
    $sql = "SELECT * 
            FROM pins 
            WHERE board_id = {$id}
            ORDER BY time DESC
            LIMIT {$start},{$numrows}
            ";
    $query  = $this->db->query($sql);
    return $query->result();
}
我假设在将变量传递给函数之前,您正在清理变量


另一种方法是传入检索到的最后一条记录的ID。这样,您就可以在上次刷新数据后添加新图像的情况下,准确地选择停止的位置。

调用此函数的函数是什么?调用的
getEachBoardPins()
的一个实例似乎不包含
$limit
。您还可以使用
$limit=“20”
,这样,如果发生这种情况,用户将只显示20个图像,而不是所有图像。是的,数值可以工作,但无限滚动仍处于不活动状态。我明白这一点。它处于非活动状态的原因是您的代码在某个地方调用了
getEachBoardPins()
,而没有
$limit
参数。您能从相关页面发布ajax代码吗?无限滚动代码大约有70行长。我将编辑包含问题的内容。您是否也可以从导致问题的页面发布此元素
#page nav a
的html。它可能有问题,阻止设置
$limit
。这可以用来提取数字,但当我到达底部图像时,无限滚动仍然不会出现。@Seth-77您需要跟踪客户端(在调用JS中)的
$start
$numrows
因此,当到达页面底部时,它可以通过最后一个位置。我已经在原始问题中添加了JS。虽然我看不到JS和函数之间有任何对应关系。@Seth-77我觉得JS是你写的。我认为你的问题更适合那些写砖石的人——我从来没有用过它,也没有用过它,也没有时间为某个人研究它