欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP ADODB实现分页功能简单示例

程序员文章站 2022-10-06 22:39:46
本文实例讲述了php adodb实现分页功能。分享给大家供大家参考,具体如下: 一、代码 adodb.inc.php可从官方网站 下载。 或者点击此处。 conn....

本文实例讲述了php adodb实现分页功能。分享给大家供大家参考,具体如下:

一、代码

adodb.inc.php可从官方网站 下载。

或者点击此处。

conn.php:

<?php
 include_once ('../adodb5/adodb.inc.php');
 $conn = adonewconnection('mysql');
 $conn -> pconnect('localhost','root','root','db_database14');
 $conn -> execute('set names gb2312');
?>

list.php:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>分页技术</title>
<style type="text/css">
<!--
th {
background-color:#ffffff;
 font-size: 12px;
 color: #ff0000;
}
td {
background-color:#ffffff;
 font-size: 12px;
 color: #ff0000;
}
a:link {
 color: #ff0000;
 text-decoration: none;
}
a:visited {
 text-decoration: none;
 color: #ff0000;
}
a:hover {
 text-decoration: none;
}
a:active {
 text-decoration: none;
}
-->
</style>
</head>
<body>
<table width="384" border="0" cellpadding="0" cellspacing="0">
 <tr>
 <td height="30">
 <?php
 include_once 'conn/conn.php';     //载入数据库链接文件
 include('../adodb5/tohtml.inc.php');   //载入tohtml.inc.php文件
 $sql = 'select * from tb_object';    //查询语句
 $num = 2;          //每页显示的记录数
 if(isset($_get['n_page'])){      //判断当前页码
  $c_page = $_get[n_page];     //将$n_page赋给变量$c_apge
 }else{
  $c_page = 1;        //初始化变量$c_page
 }
 $rst = $conn -> pageexecute($sql,$num,$c_page); //执行pageexecute函数
 if(false != $rst){
  if(!$rst -> atfirstpage()){     //如果当前页不是首页
?><!-- 输出向上翻页超链接 -->
  <a href ="<?php echo '?n_pge=1' ?>"> 首页 </a>
  <a href ="<?php echo '?n_page='.($rst -> absolutepage() - 1); ?>"> 上一页 </a>
<!-- ---------------------------- -->
<?php
  }
  if(!$rst -> atlastpage()){     //如果当前页不是尾页
?>
<!-- 输出向下翻页超链接 -->
  <a href = "<?php echo '?n_page='.($rst -> absolutepage() + 1); ?>"> 下一页 </a>
  <a href ="<?php echo '?n_page='.($rst -> lastpageno());?>"> 尾页 </a>
<!-- ----------------------------- -->
<?php
  }
?></td>
 </tr>
 <tr>
 <td><?php
  rs2html($rst,'width=350 border="1" cellpadding="1" cellspacing="1" bordercolor="#ffffff" bgcolor="#ff0000"',array('id','类型','添加时间'));
 ?></td>
 </tr><?php }?>
 <tr>
 <td height="30">当前是第<?php echo $rst -> absolutepage(); ?>页/一共是<?php echo $rst -> lastpageno(); ?>页</td>
 </tr>
</table>
</body>
</html>

二、运行结果

PHP ADODB实现分页功能简单示例

更多关于php相关内容感兴趣的读者可查看本站专题:《php+mysql数据库操作入门教程》、《php基于pdo操作数据库技巧总结》、《php+mongodb数据库操作技巧大全》、《php+oracle数据库程序设计技巧总结》、《php+mssql数据库程序设计技巧总结》、《php+redis数据库程序设计技巧总结》、《php+mysqli数据库程序设计技巧总结》及《php常见数据库操作技巧汇总

希望本文所述对大家php程序设计有所帮助。