page.php
[php]
<?php
$conn=@mysql_connect("127.0.0.1","root","lzgabc123") or die("数据链接出错");
mysql_select_db("ghgl",$conn);
mysql_query("set names ‘utf8’");
?>
<script>
function daojishi(id) {
var t = Math.floor($("#" + id).attr(‘rel’));
t–;
var d = Math.floor(t / 60 / 60 / 24);
var h = Math.floor(t / 60 / 60 % 24);
var m = Math.floor(t / 60 % 60);
var s = Math.floor(t % 60);
if (d < 10) {
d = ‘0’ + d;
}
if (h < 10) {
h = ‘0’ + h;
}
if (m < 10) {
m = ‘0’ + m;
}
if (s < 10) {
s = ‘0’ + s;
}
$("#" + id).attr(‘rel’, t);
$("#" + id).html(d + ‘:’ + h + ‘:’ + m + ‘:’ + s);
}
</script>
<?php
require "conn.php";
$maxnum = 20; //每页记录条数
$sql_count = "SELECT COUNT(*) AS count FROM xy_cust";
$result=mysql_query($sql_count);
if($result)
{
$row1 = mysql_fetch_assoc($result);
$totalRows1 = $row1[‘count’]; //数据集总条数
$totalpages = ceil($totalRows1/$maxnum);//分页总数
if(!isset($_GET[‘page’]) || !intval($_GET[‘page’]) || $_GET[‘page’] > $totalpages) $page = 1; //对3种出错进行处理
//在url参数page不存在时,page不为10进制数时,page大于可分页数时,默认为1
else $page = $_GET[‘page’];
$startnum = ($page – 1)*$maxnum; //从数据集第$startnum条开始读取记录,这里的数据集是从0开始的
$query = "SELECT * FROM xy_cust LIMIT $startnum,$maxnum";//选择出符合要求的数据 从$startnum条数据开始,选出$maxnum行
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$xm=$row[‘xingming’];
$title=$row[‘title’];
$content=<<< content
<p style=’height:66px;font-size:50px;’>{$xm}{$title}</p>
content;
echo $content;
}
}
?>
[/php]
index.html 访问页面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="jquery.min.js"></script> <script> var niulock = 1; var niunum = 1; function loaddata(page, obj, sc) { var link = page.replace('0000', niunum); // showLoader('正在加载中....'); $.get(link, function (data) { if (data != 0) { obj.append(data); } niulock = 0; // hideLoader(); }, 'html'); if (sc === true) { $(window).scroll(function () { var wh = $(window).scrollTop(); var xh = $(document).height() - $(window).height() - 70; if (!niulock && wh >= xh ) { niulock = 1; niunum++; var link = page.replace('0000', niunum); // showLoader('正在加载中....'); var timeout = setTimeout(function(){ niulock = 0; // hideLoader(); },5000); $.get(link, function (data) { if (data != 0) { if(timeout){ //清除定时器 clearTimeout(timeout); timeout = null; } obj.append(data); } niulock = 0; // hideLoader(); }, 'html'); } }); } } </script> <script> $(document).ready(function () { loaddata('page.php?page=0000',$("#content"), true); }); </script> </head> <body> <div id="content"> </div> </body> </html>