码迷,mamicode.com
首页 > Web开发 > 详细

php翻页

时间:2014-05-19 13:42:33      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:c   int   a   get   数据   set   

<?php
$conn = mysql_connect("localhost","root","") or die("连接数据库失败!");
mysql_select_db("test");
mysql_query("set names ‘utf8‘");

$page = "";
if(@$_GET[‘page‘]){
$page = $_GET[‘page‘];
}else{
$page = 1;
}
$pageSize = 2;
//$sum = ($page-1)*$pageSize;
$parentid = 0;
$sum = ($page-1)*$pageSize;
$sql = "select * from tiezi where pid = 0 limit $sum,$pageSize";

$r = "select * from tiezi where pid = 0";
$r = mysql_query($sql);
$count = count($r);
?>

<a href="zhutie.php?page=<?php echo $page-1 ?>">上一页</a>
<?php
$totalPage = $count % $pageSize == 0 ? intval($count / $pageSize) : intval($count / $pageSize) + 1;
for($i=1;$i<=$totalPage;$i++){
?>
<a href="zhutie.php?page=<?php echo $i ?>"><?php echo $i ?></a>
<?php
}
?>
<a href="zhutie.php?page=<?php if($page >= $totalPage){echo $totalPage;}else{echo $page+1;} ?>">下一页</a>

php翻页,布布扣,bubuko.com

php翻页

标签:c   int   a   get   数据   set   

原文地址:http://www.cnblogs.com/pulang/p/3735396.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!