Home > Backend Development > PHP Tutorial > How to use PHP ADODB to create paging function

How to use PHP ADODB to create paging function

php中世界最好的语言
Release: 2023-03-28 09:18:02
Original
1324 people have browsed it

This time I will show you how to use PHP ADODB to create paging function, what are the notes of using PHP ADODB to create paging function, the following is a practical case, let’s take a look take a look.

1. Code

adodb.inc.php can be downloaded from the official website http://adodb.sourceforge.net/.

Or click hereDownload from this site.

conn.php:

<?php
 include_once (&#39;../adodb5/adodb.inc.php&#39;);
 $conn = ADONewConnection(&#39;mysql&#39;);
 $conn -> PConnect('localhost','root','root','db_database14');
 $conn -> execute('set names gb2312');
?>
Copy after login

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 &#39;conn/conn.php&#39;;     //载入数据库链接文件
 include(&#39;../adodb5/tohtml.inc.php&#39;);   //载入tohtml.inc.php文件
 $sql = &#39;select * from tb_object&#39;;    //查询语句
 $num = 2;          //每页显示的记录数
 if(isset($_GET[&#39;n_page&#39;])){      //判断当前页码
  $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 &#39;?n_pge=1&#39; ?>"> 首页 </a>
  <a href ="<?php echo &#39;?n_page=&#39;.($rst -> AbsolutePage() - 1); ?>"> 上一页 </a>
<!-- ---------------------------- -->
<?php
  }
  if(!$rst -> AtlastPage()){     //如果当前页不是尾页
?>
<!-- 输出向下翻页超链接 -->
  <a href = "<?php echo &#39;?n_page=&#39;.($rst -> AbsolutePage() + 1); ?>"> 下一页 </a>
  <a href ="<?php echo &#39;?n_page=&#39;.($rst -> LastPageNo());?>"> 尾页 </a>
<!-- ----------------------------- -->
<?php
  }
?></td>
 </tr>
 <tr>
 <td><?php
  rs2html($rst,&#39;width=350 border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FF0000"&#39;,array(&#39;ID&#39;,&#39;类型&#39;,&#39;添加时间&#39;));
 ?></td>
 </tr><?php }?>
 <tr>
 <td height="30">当前是第<?php echo $rst -> AbsolutePage(); ?>页/一共是<?php echo $rst -> LastPageNo(); ?>页</td>
 </tr>
</table>
</body>
</html>
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website !

Recommended reading:

How to implement ADODB transaction processing in PHP

How to use Thinkphp5 uploadify to implement file upload

The above is the detailed content of How to use PHP ADODB to create paging function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template