sql >> Database teknologi >  >> RDS >> Mysql

Infinite Scroll Indlæser alle elementer på én gang?

Du glemmer at indstille LIMIT i mySQL-anmodning og i url-generator:

PHP

<?php
$link = mysql_pconnect("localhost", "user", "pass") or die("Could not connect");
mysql_select_db("dbase") or die("Could not select database");

//GET page/count
$count=10;$offset=0;
if (isset($_GET['count'])) $count=$_GET['count']*1;
if (isset($_GET['page']))  $offset=$_GET['page']*$count*1;

$arr = array();

$rs = mysql_query("SELECT * FROM bannersright 
                   ORDER BY HdOrder 
                   LIMIT $offset,$count"); #<-HERE

while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}

echo '{"bannersright":'.json_encode($arr).'}';

?>

JS:

$(function () {

        $("#wrapper #sidebar-right").autobrowse(

            {

                url: function (offset)
                {                   
                    return "http://www.mysite.com/json.php?count=10&page="
                           +Math.round(offset/10); // <-- AND HERE
                },
                template: function (response)
                {
                    var markup='';
                    for (var i=0; i<response.bannersleft.length; i++)
                    {
                        markup+='<a href="'+response.bannersleft[i].URL+'"><img src="'+response.bannersleft[i].Image+'" /></a>'
                    };
                    return markup;
                },
                itemsReturned: function (response) { return response.bannersleft.length; },
                offset: 0,
                max: 1,
                loader: '<div class="loader"></div>',
                useCache: false,
                expiration: 1
            }
        );

});



  1. I SQL Server, hvordan man pivoterer for flere kolonner

  2. Hvordan opretter man en pdf-fil med mysql-data?

  3. Skal jeg bruge C3P0 pooling-bibliotek i min (grails) webapplikation?

  4. Advarsel:mysql_connect():Kan ikke oprette forbindelse til lokal MySQL-server