php 和html 混编 看起来真是 DT
文件名为t1.php 已经过调试 没有加错误捕捉 表名 tttt
header("Content-Type: text/html; charset=utf-8");
$dbhost ="127.0.0.1";
$dbuser = "root";
$dbpwd = "*****";
$dbname = "*****";
$charName = "'UTF8'"; //设置查询字符集gbk,gbk2312,utf-8
$mysqli = new mysqli($dbhost,$dbuser,$dbpwd,$dbname);
if (mysqli_connect_errno()){ //注意mysqli_connect_error()新特性
die('Unable to connect!'). mysqli_connect_error();
}
$sql = "SET NAMES ".$charName;
$mysqli->query($sql);
$perNumber=50; //每页显示的记录数
$page=isset($_GET['page'])?$_GET['page']: 1 ; //获得当前的页面值
//echo $page;
$sql="select count(*) as count from tttt";
$rs=$mysqli->query($sql); //获得记录总数
$row=mysqli_fetch_array($rs,MYSQLI_ASSOC) ;
$totalNumber=$row['count'];
$totalPage=ceil($totalNumber/$perNumber); //计算出总页数
$startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录
$result=$mysqli->query("select * from tttt order by id desc limit $startCount,$perNumber"); //根据前面的计算出开始的记录和记录数
$maxPageCount=10;
$buffCount=5;
$startPage=1;
if ($page< $buffCount){
$startPage=1;
}else if($page>=$buffCount and $page<$totalPage-$maxPageCount ){
$startPage=$page-$buffCount+1;
}else{
$startPage=$totalPage-$maxPageCount+1;
}
$endPage=$startPage+$maxPageCount-1;
$htmlstr="";
$line=1;
while ($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
$htmlstr.=$line."行";
$htmlstr.=$row['id']." ";
$line++;
}
$htmlstr.="
第一页 | ";上一页 | ";".$i." | ";下一页 | ";最后页 | ";