小结

验证数据库

<?php
include("conn.php");

$sql = "select * from shuju";

$result = mysql_query($sql);
$count = mysql_num_rows($result);
$pageSize = 2;

$totalPage = $count % $pageSize == 0 ? (int)($count / $pageSize):(int)($count / $pageSize)+1;

$page = 0;
if(isset($_GET['page'])){
$page = $_GET['page'];
}else{
$page = 1;
}

$pagePos = ($page - 1) * $pageSize;

 

$sql = "select * from shuju limit $pagePos,$pageSize";
$result = mysql_query($sql);
?>

翻页

共有<?php
echo $count;
?>条数据&nbsp;&nbsp;&nbsp;
共有<?php
echo $totalPage;
?>页&nbsp;&nbsp;&nbsp;

<?php
for($i=1;$i<=$totalPage;$i++){
?>
<a href="booklist.php?page=<?php echo $i; ?>"><?php echo $i; ?></a>&nbsp;&nbsp;
<?php } ?>


<a href="booklist.php?page=<?php if($page >= $totalPage){echo $totalPage;}else{ echo $page+1;} ?>">下一页</a>

跳转到 <input type="text" name="" onkeyup="this.value=this.value.replace(/\D/g,'')" id="jumpPage" maxlength="3" size="3"/>页
</body>
<script>
var jp = document.getElementById("jumpPage");
jp.onkeydown = function(e){
var e = e || window.event;
if(e.keyCode == 13){
location.href = "booklist.php?page="+jp.value;
}
}

posted @ 2014-05-24 12:11  三月迷离  阅读(93)  评论(0编辑  收藏  举报