PHP Dynamic Scrolling Loading instance

Source: Internet
Author: User

Included: PHP, pagination, jquery, div+css

Example Download: http://download.csdn.net/detail/roro5119/7373905

index.php

<?//Database configuration fileinclude("conn.php");//default Search$page=$_get["Page"]?$_get["Page"]: 1;$pagesize= 20;$pageval= ($page-1) *20;$sql= "Select ' Pic ' from ' mypic ' limit$pageval,$pagesize";$query=mysql_query($sql);? ><! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >Auto;} . Showbox img{padding:5px; background:#CCCCFF;}. add-more{width:1000px; background:yellow;height:100px; line-height:30px; text-align:center; margin:0 auto; display :none;}</style><body><divclass= "Showbox" &GT;&LT;? while($row=Mysql_fetch_array($query)){? >$row["pic"];? > "width=" "height=" ">&lt";?    }?></div><!--Data loading hints, default hidden--><divclass= "Add-more" > Data loading ...</div><!--js section--><script type= "Text/javascript" >    $(function(){        vardownrange = 100;//bottom Boundary-reference loading cue layer/px        varnum = <?=$page;? >;//Initial page Number        varMaxnum = num+5;//Set load times        var $main= $ (". Showbox");//Main body        var $loaddiv= $ (". Add-more")//load Cue layer        varTotalheight = 0; //to determine whether an asynchronous        functionifload () {//distance from top of scroll bar            varScrolltotop=parsefloat ($ (window).scrolltop ()); //Window Height            varWinheight = parsefloat ($ (window).height ()); //Total Content Height            varConheight = parsefloat ($ (document). Height ())-downrange; //Total HeightTotalheight = Scrolltotop +Winheight; //decide whether to load, when the operation height is larger than the content, and the space is ample            if(Totalheight >= conheight && num!=maxnum)                {ajaxload (num); Num++; }        }        //Ajax-fun        functionajaxload (page) {$.Ajax ({URL: "Ajax.php",type: "Post",Data: {Page:page,maxnum:maxnum},Success:function(Result) {//Append Data                        $main.append (result); }            })        }        //hide display in load        $loaddiv. Ajaxstart (function() {$ (this).Show (); }). Ajaxstop (function() {$ (this).Hide (); })        //Scroll-fun$ (window).Scroll (ifload); })</script></body>

Asynchronous files:

<?//Database configuration fileinclude("conn.php");//Display information per page$pagesize=20;//Maximum load times$maxnum=$_post["Maxnum"]-1;//from where to start$page=$_post["Page"];$nextpagestart=$page*$pagesize;$sql= "Select ' Pic ' from ' mypic ' limit$nextpagestart,$pagesize";$query=mysql_query($sql); while($row=Mysql_fetch_array($query)){    //content? >$row["pic"];? > "width=" "height=" ">&lt";?}//page Outif($page==$maxnum){    include(' page.class.php '); $sqlsum= "Select ' id ' from ' mypic '"; $querysum=mysql_query($sqlsum); //Total Data    $total=mysql_num_rows($querysum); //parameters corresponding to location: Total record, number of bars per page, current page, connected address    $my _page=NewPageclass ($total,$pagesize,$page, '? Page={page} '); //Output page Number    Echo $my _page-Myde_write (); Exit;}?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.