sql >> Database >  >> RDS >> Mysql

Oneindig scrollen Alle items tegelijk laden?

Je vergeet LIMIT in te stellen in het mySQL-verzoek en in de 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. Hoe REVERSE() werkt in MariaDB

  2. mysql_fetch_array haalt niet alle rijen op

  3. Slaapstand> CLOB> Oracle :(

  4. Hoe kan ik alleen de eerste afzonderlijke overeenkomst uit een veld in MySQL selecteren?