PHP分页
2015-04-28 14:18
134 查看
<?php$conn=mysql_connect("localhost","root","");//$result2=mysql_db_query("hello_world", "insert into hello_table values ('add1',8)",$conn);// $result2=mysql_db_query("hello_world", "delete from hello_table where hello_column='add1'",$conn);$resultNum=mysql_db_query("hello_world","select count(*) from hello_table order by hello_column" ,$conn);$RSS=mysql_fetch_array($resultNum);$num=$RSS[0];if(empty($_GET['page'])){$page=0;}else{$page=$_GET['page'];if($page<0){$page=0;}if($page>=ceil($num/5)){$page=ceil($num/5)-1;} }$excute="select * from hello_table order by hello_column limit ".($page*5).",5 ";$result=mysql_db_query("hello_world",$excute ,$conn);$row=mysql_fetch_row($result);for($i=0;$i<mysql_num_fields($result);$i++){echo mysql_field_name($result, $i)." ";}echo "<br>";while($row=mysql_fetch_row($result)){for($i=0;$i<mysql_num_fields($result);$i++){echo $row[$i]." ";}echo "<br>";}mysql_free_result($result);mysql_close($conn);
?>
<a href="test.php?page=0">FirstPage</a>
<a href="test.php?page=<?=($page-1) ?>">PrevPage</a>
<a href="test.php?page=<?=($page+1) ?>">NextPage</a>
<a href="test.php?page=<?=ceil($num/5)-1 ?>">LastPage</a>
=====================================================================
怎么分段,当前在第几段 (每页有几条,当前再第几页) 前10条记录:select * from table limit 0,10 第11至20条记录:select * from table limit 10,10 第21至30条记录:select * from table limit 20,10
(当前页数 - 1 )X 每页条数 , 每页条数Select * from table limit ($Page- 1) * $PageSize, $PageSize
?>
<a href="test.php?page=0">FirstPage</a>
<a href="test.php?page=<?=($page-1) ?>">PrevPage</a>
<a href="test.php?page=<?=($page+1) ?>">NextPage</a>
<a href="test.php?page=<?=ceil($num/5)-1 ?>">LastPage</a>
=====================================================================
怎么分段,当前在第几段 (每页有几条,当前再第几页) 前10条记录:select * from table limit 0,10 第11至20条记录:select * from table limit 10,10 第21至30条记录:select * from table limit 20,10
(当前页数 - 1 )X 每页条数 , 每页条数Select * from table limit ($Page- 1) * $PageSize, $PageSize
相关文章推荐
- 基于PHP多维数组的分页实现(可用于在线购物车等应用)
- php mssql几条常见的数据库分页 SQL 语句
- php学习笔记(13):PHP+MYSQL简单分页
- PHP结合MYSQL记录结果分页呈现(比较实用)
- ThinkPHP3.1.2的DbOracle.class.php不能实现分页的解决方法
- PHP写的一个比较完善的分页.
- PHP通用分页
- PHP分页及原理
- PHP+MYSQL分页原理
- php+MySQL简单的网页分页功能
- PHP自动适应范围的页码分页程序
- PHP+MySQL分页原理实现
- 一个典型的PHP分页实例代码
- php 分页原理
- 用PHP生成html分页列表的代码
- php分页示例代码
- 分享一个PHP分页代码
- PHP多条件搜索之后,对搜索集进行分页设置,避免了点击“上一页”或“下一页”后出现不是所要查询的内容
- PHP基于数组的分页函数(核心函数array_slice())
- 一个典型的PHP分页实例代码分享