怎么在PHP中使用ADODB实现一个分页功能示例

发布时间:2021-04-07 17:50:07 作者:Leah
来源:亿速云 阅读:143

这篇文章将为大家详细讲解有关怎么在PHP中使用ADODB实现一个分页功能示例,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

一、代码

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中使用ADODB实现一个分页功能示例就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. 怎么在iOS中实现一个分页加载功能
  2. 使用php怎么实现分页功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php adodb

上一篇:怎么在Spring Boot中创建一个Web应用程序

下一篇:如何在Django中使用rest framework实现分页

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》