溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么在PHP中使用ADODB實現(xiàn)一個分頁功能示例

發(fā)布時間:2021-04-07 17:50:07 來源:億速云 閱讀:153 作者:Leah 欄目:開發(fā)技術(shù)

這篇文章將為大家詳細講解有關(guān)怎么在PHP中使用ADODB實現(xiàn)一個分頁功能示例,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

一、代碼

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>分頁技術(shù)</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>

二、運行結(jié)果

怎么在PHP中使用ADODB實現(xiàn)一個分頁功能示例

關(guān)于怎么在PHP中使用ADODB實現(xiàn)一個分頁功能示例就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI