mysql+php分頁(yè)類(lèi)(已測(cè))
更新時(shí)間:2008年03月31日 19:15:23 作者:
三個(gè)參數(shù)。 mysql_query()的結(jié)果, url變量page, 您要的每頁(yè)記錄數(shù)
例子在這個(gè)文件底部
淡水河邊整理測(cè)試
復(fù)制代碼 代碼如下:
<?php
/*
mysql_pager.class.php
三個(gè)參數(shù)。 mysql_query()的結(jié)果, url變量page, 您要的每頁(yè)記錄數(shù)
例子在這個(gè)文件底部
淡水河邊整理測(cè)試
*/
class mysql_pager {
// define properties
var $page;
var $result;
var $results_per_page = 3;
var $total_pages;
/*
Define the methods
下面是構(gòu)造函數(shù),和類(lèi)同名(>php4)
需要查詢的結(jié)果句柄,當(dāng)前頁(yè)碼,每頁(yè)記錄數(shù)
like: $f->mysql_pager($result, 1, 15);
*/
function mysql_pager( $result, $current_page, $results_per_page ) {
if(!$result){
echo "<div align=center>數(shù)據(jù)庫(kù)未運(yùn)行,結(jié)果集錯(cuò)誤</div>\n";
return;
}
$this->result = $result;
if(!$current_page || $current_page < 0)
$this->page = 1;
else $this->page = $current_page;
if(!emptyempty($results_per_page))
$this->results_per_page = $results_per_page;
$numrows = @mysql_num_rows($this->result);
if(!$numrows) {
echo "<div align=center>查詢結(jié)果為空.</div>\n";
return;
}
$this->total_pages = ceil($numrows / $this->results_per_page);
}
/*
下面是打印內(nèi)容的函數(shù),可以不用,也可以根據(jù)自己的需要擴(kuò)展
這里只是打印出id
*/
function print_paged_results() {
echo "<table border=0 align=center>\n";
$start = ($this->page - 1) * $this->results_per_page;
mysql_data_seek($this->result, $start);
$x = 0;
for($i = 1; $i <= $this->results_per_page && $row = @mysql_fetch_array($this->result); $i++) {
if($x++ & 1) $bgcolor = "#F2F2FF";
else $bgcolor = "#EEEEEE";
echo "<tr bgcolor=$bgcolor><td>". $row["id"] . "</td></tr>";
// 編輯這部分輸出任何您想要的HTML
}
echo "</table>\n";
}
/*
下面是打印頁(yè)碼和鏈接的函數(shù)
在我們需要顯示頁(yè)碼的地方調(diào)用
*/
function print_navigation() {
global $PHP_SELF;
echo "<div align=center>";
for($i = 1; $i <= $this->total_pages; $i++) { #loop to print << 1 2 3... $total_pages >>
if($i == 1 && $this->page > 1) #Prints the << first to goto the previous page (not on page 1)
echo "<a href=\"$PHP_SELF?page=".($this->page - 1)."\" onMouseOver=\"status="Previous Page";return true;\" onMouseOut=\"status=" ";return true;\">?</a>";
if($i == $this->page) #Doesn"t print a link itself, just prints page number
echo "<font color=\"#ff3333\"> $i </font>";
if($i != $this->page) #Other links that aren"t this page go here
echo "<a href=\"$PHP_SELF?page=$i\" onMouseOver=\"status="Go to Page $i";return true;\" onMouseOut=\"status=" ";return true;\"> $i </a>";
if($i == $this->total_pages && $this->page != $this->total_pages) # Link for next page >> (not on last page)
echo "<a href=\"$PHP_SELF?page=".($this->page + 1)."\" onMouseOver=\"status="Go to the Next Page";return true;\" onMouseOut=\"status=" ";return true;\">?</a>";
}
echo "</div>\n";
}
}
/*
mysql_connect($server, $uname, $pass );
mysql_select_db("$db");
$result= @mysql_query("Select * FROM table");
$p = new mysql_pager( $result, $page=$_GET["page"], 10 );
$p->print_navigation();
$p->print_paged_results();
$p->print_navigation();
*/
?>
您可能感興趣的文章:
- PHP封裝的分頁(yè)類(lèi)與簡(jiǎn)單用法示例
- PHP分頁(yè)顯示的方法分析【附PHP通用分頁(yè)類(lèi)】
- php封裝的page分頁(yè)類(lèi)完整實(shí)例
- PHP實(shí)現(xiàn)的簡(jiǎn)單分頁(yè)類(lèi)及用法示例
- 精美漂亮的php分頁(yè)類(lèi)代碼
- PHP通用分頁(yè)類(lèi)page.php[仿google分頁(yè)]
- 兩款萬(wàn)能的php分頁(yè)類(lèi)
- 高效mongodb的php分頁(yè)類(lèi)(不使用skip)
- PHP ajax 分頁(yè)類(lèi)代碼
- 仿dedecms下拉分頁(yè)樣式修改的thinkphp分頁(yè)類(lèi)實(shí)例
- PHP基于面向?qū)ο蠓庋b的分頁(yè)類(lèi)示例
相關(guān)文章
學(xué)習(xí)php設(shè)計(jì)模式 php實(shí)現(xiàn)適配器模式
這篇文章主要介紹了php設(shè)計(jì)模式中的適配器模式,使用php實(shí)現(xiàn)適配器模式,感興趣的小伙伴們可以參考一下2015-12-12PHP獲取當(dāng)前頁(yè)面URL函數(shù)實(shí)例
這篇文章主要介紹了PHP獲取當(dāng)前頁(yè)面URL函數(shù)實(shí)例,講述了一個(gè)非常簡(jiǎn)單實(shí)用的獲取當(dāng)前頁(yè)面URL的函數(shù),并附帶說(shuō)明了server參數(shù)的用法,需要的朋友可以參考下2014-10-10php中ob(Output Buffer 輸出緩沖)函數(shù)使用方法
php中ob(Output Buffer 輸出緩沖)函數(shù)使用方法...2007-07-07