php分页
<?php header("content-type:text/html;charset=utf-8"); mysql_connect("127.0.0.1","root","") or die("连接失败");//连库 mysql_select_db("demo"); mysql_query("set names utf-8"); $sql = "select * from user"; $res = mysql_query($sql); $count = mysql_num_rows($res);//表中数据总数 $size = 4;//每页显示的条数 $page = isset($_GET['page'])?$_GET['page']:1;//当前页 if($page-1<=1){ $last = 1; }else{ $last = $page-1; } //$down = $page+1;//下一页 $last = ceil($count/$size);//尾页 $offset = ($page-1)*$size;//偏移量(开始位置) $sql = "select * from user limit $offset,$size"; //第一页 从0 4条//4 4 $res = mysql_query($sql); $arr = ""; while($data = mysql_fetch_assoc($res)){ $arr[] = $data; } ?> <table border="1"> <tr> <td>ID</td> <td>用户名</td> <td>手机号</td> </tr> <?php foreach($arr as $v){ ?> <tr> <td><?php echo $v['user_id']?></td> <td><?php echo $v['user_name']?></td> <td><?php echo $v['tel']?></td> </tr> <?php } ?> </table> <a href="show.php?page=1">首页</a> <?php if($page>1){?> <a href="show.php?page=<?php echo $up ?>">上一页</a> <?php } ?> <?php for($i=1;$i<=$last;$i++){ ?> <a href="show.php?page=<?php echo $i?>"><?php echo $i?></a> <?php } ?> <?php if($page<$last){?> <a href="show.php?page=<?php echo $down ?>">下一页</a> <?php } ?> <a href="show.php?page=<?php echo $last ?>">尾页</a>
通往牛逼的路上,在意的只有远方!