PHP分页技术详解
2014-01-24 10:55
316 查看
直接上代码,注释很详细了。
效果图:
demo可以在 PHP分页demo 下载。
<?php /** * php分页技术详解 * @author jahng */ header("Content-type: text/html; charset=UTF-8"); echo'<link rel="stylesheet" type="text/css" href="css.css" media="all" />'; require_once('page.php'); $db = @mysql_connect("localhost","root","haojiang"); if($db==false){ exit("连接数据库失败!"); } if(!mysql_select_db("gbook", $db)){ exit("gbook数据库不存在!"); } //从数据库获取将要分页的数据的总记录数 $result=mysql_query("SELECT COUNT(*) AS c FROM message"); $allRecord=mysql_fetch_assoc($result); $count=$allRecord['c']; //获取当前页 $currentPage=isset($_GET['page'])?intval($_GET['page']):1; //每页显示五条记录 $limit=5; //计算当前页的第一条数据在数据库中的id $start=($currentPage-1)*$limit; //从数据库获取当前页将要显示的数据 $sql="SELECT * FROM message LIMIT $start,$limit"; $result=mysql_query($sql); $message=array(); if($result && mysql_num_rows($result)!=0){ while($r=mysql_fetch_assoc($result)){ $message[]=$r; } } //简单的留言显示 foreach($message as $item){ echo "<dt>".date('Y-m-d h:i:s',$item['time'])." ".$item['name']."</dt>"; echo "<dd>".$item['content']."</dd>"; } //分页链接 echo page($currentPage,$count,$limit,5,$class='sabrosus'); ?>
效果图:
demo可以在 PHP分页demo 下载。
相关文章推荐
- ftp命令行上传文件
- PHP弹出提示框,并跳转到新页面(重定向)
- php+cookie 实现购物车
- 让你的Yii程序连接mysql数据库
- PHP面向对象程序设计的61条黄金法则
- Yii主题的简单操作
- php中sql注入漏洞示例 sql注入漏洞修复
- php解析XML和AJAX时乱码问题的解决
- js标签引入php文件
- GetTextExtentPoint32 函数的使用
- Yii Zii组件 CGridView 使用详解
- ftp无法连接的可能原因
- 建立第一个 Yii 应用
- lamp环境下php加速
- Yii: URL管理规则中命名参数使用注意点
- PHP的session存储对PHP运行环境的影响
- 使用PHP创建一个REST API(Create a REST API with PHP)
- PHP自学教程之PHP加密函数
- php中sql注入漏洞示例 sql注入漏洞修复
- php实现邮件发送并带有附件