PHP ADODB實現(xiàn)分頁功能簡單示例
本文實例講述了PHP ADODB實現(xiàn)分頁功能。分享給大家供大家參考,具體如下:
一、代碼
adodb.inc.php可從官方網站http://adodb.sourceforge.net/ 下載。
或者點擊此處本站下載。
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'; //載入數(shù)據(jù)庫鏈接文件
include('../adodb5/tohtml.inc.php'); //載入tohtml.inc.php文件
$sql = 'select * from tb_object'; //查詢語句
$num = 2; //每頁顯示的記錄數(shù)
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); //執(zhí)行pageExecute函數(shù)
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相關內容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《PHP基于pdo操作數(shù)據(jù)庫技巧總結》、《PHP+MongoDB數(shù)據(jù)庫操作技巧大全》、《php+Oracle數(shù)據(jù)庫程序設計技巧總結》、《php+mssql數(shù)據(jù)庫程序設計技巧總結》、《php+redis數(shù)據(jù)庫程序設計技巧總結》、《php+mysqli數(shù)據(jù)庫程序設計技巧總結》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
相關文章
PHP的郵件群發(fā)系統(tǒng)phplist配置方法詳細總結
這篇文章主要介紹了PHP郵件群發(fā)系統(tǒng)phplist配置方法,結合實例形式詳細總結分析了PHP郵件群發(fā)系統(tǒng)phplist的配置與使用技巧,需要的朋友可以參考下2016-03-03
PHP+MySQL使用mysql_num_rows實現(xiàn)模糊查詢圖書信息功能
這篇文章主要介紹了PHP+MySQL使用mysql_num_rows實現(xiàn)模糊查詢圖書信息功能,涉及php使用mysql的like查詢語句進行模糊查詢以及mysql_num_rows進行結構統(tǒng)計的相關操作技巧,需要的朋友可以參考下2018-05-05
PHP基于遞歸實現(xiàn)的約瑟夫環(huán)算法示例
這篇文章主要介紹了PHP基于遞歸實現(xiàn)的約瑟夫環(huán)算法,結合實例形式較為詳細的分析了約瑟夫環(huán)問題與php使用遞歸算法的解決方法,需要的朋友可以參考下2017-08-08

