php 和html 混编 看起来真是 DT
文件名为t1.php 已经过调试 没有加错误捕捉 表名 tttt
<?phpheader("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']." </br>"
$line++
}
$htmlstr.="<table><tr>"
if ($page > 1){
$htmlstr.="<td> <a href='t1.php?page=". 1 ."' >第一页</a> </td>"
$htmlstr.="<td> <a href='t1.php?page=". ($page-1) ."' >上一页</a> </td>"
}
for ($i=$startPage$i<=$endPage $i++){
$htmlstr.="<td><a href='t1.php?page=".$i."'>".$i."</a></td>"
}
if ($page<$totalPage){
$htmlstr.="<td><a href='t1.php?page=".($page+1) . "' >下一页</a> </td>"
$htmlstr.="<td><a href='t1.php?page=".$totalPage . "' >最后页</a> </td>"
}
$htmlstr.="</tr></table>"
echo $htmlstr
?>
if($i==$page){$key.=' <span>'.$i.'</span>'
} else {
$key.=" <a href=\"".$_SERVER['PHP_SELF']."?page=".$i."\">".$i."</a>"
}
改成
if($i==$page){
$key.=' <span style="color:red">'.$i.'</span>'
} else {
$key.=" <a href=\"".$_SERVER['PHP_SELF']."?page=".$i."\">".$i."</a>"
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)