検索
ホームページphp教程php手册私の php_mysql ページング クラスの 1 つ

mysql|ページネーション

class RSPage {
var $Debug = 0;
var $sqoe = 1; // sqoe= エラー時にクエリを表示
var $Link_ID = 0;
var $Record = array();
var $Row;
var $numRow;
var $Parse;
var $Error = "";
var $ m_timeFmt = "YYYY-MM-DD HH24:MI:SS";

var $m_num=-1;
var $m_sql;
var $m_pageSize=10;
var $m_cmt;
var $m_curPage=1;
function open($DB_Link)
{
$this->Link_ID = $DB_Link;
}

関数クエリ($Query_String,$ page=1,$cnt=-1,$size=10) {
if($Query_String=="")
{
echo "执行语句不可空!";
return false;
}
if( !$ page)
$page = 1;
if(!$cnt)
$cnt = -1;
$this->m_pageSize = $size;

if($this->Parse){
mysql_free_result($this ->Parse);
}

if($cnt!=-1){
$this->m_num = $cnt;
else{
$result = mysql_query($Query_String, $this-> Link_ID);
if(!$result){
$this->Error=mysql_error($this->Link_ID);
}
else{
else{
$this->m_num = mysql_num_rows($result);
}
/*
$cntsql = "($Query_String) から count(*) max_num を選択";
$maxnum = 0;
$result = mysql_query($sqlstr,$this-& gt;Link_ID);
$ret = mysql_fetch_array( $result);
mysql_free_result($result);
if(!$ret) {
$this->Error=mysql_error($this->Link_ID);
}
else {
$this->m_num = $ret["max_num"];
}
*/

$pageCount = $this->getPageCount();
$pageSize = $ this->getPageSize();
if($page>$pageCount )$page=$pageCount;
        if($page $this->m_curPage=$page;
$posBegin = ($page-1)*$pageSize;
$posEnd = $posBegin + $pageSize;
$Query_String = "$Query_String LIMIT $posBegin,$posEnd";
$this->Parse=mysql_query($Query_String,$this->Link_ID);

if(!$this->Parse) {
$this- >Error=mysql_error($this->Link_ID);
}
$this->Row=0;

if($this->Debug) {
printf("デバッグ: query = %s
}

if ($this->エラー && $this->sqoe)
echo "
".$this ->エラー["メッセージ"]."
クエリ:"$Query_String"
";
$numRow=mysql_num_rows($this->Parse);
return $ this->Parse;
}
function setTimeFormat($timestr){
$this->m_timeFmt = $timestr;
}
function next_record() {
if(!($row = mysql_fetch_array($this->> Parse))) {
mysql_free_result($this->Parse);
$this->Parse = false;
$stat=0;
else {
else while(list($key,$val)=each ($row)) {
$colreturn=strto lower($key);
$this->Record[ "$colreturn" ] = $val;
if($this->Debug) echo"[ $key]:".$val."
n";
}
$stat=1;
}

return $stat;
}

function record_exist() {
if( 0 == mysql_num_rows($this->Parse)) {
return 0;
} else {
return 1;
}

return $stat;
}

関数 Seek($pos) {
$this-> ;Row=$pos;
}

functionaffected_rows() {
return mysql_affected_rows($this->Parse);
}

function num_rows() {
return mysql_num_rows($this-> ;解析);
}

function f($Name) {
return $this->Record[$Name];
}

function p($Name) {
print $this->Record[$Name];
}

function close() {
if($this->Debug) {
//printf("切断中...
n");
}
if($this->Parse){
mysql_free_result ( $this->Parse);
}
//mysql_close($this->Link_ID);
}

//---public 得到当前页
function getCurPage(){return $this->m_curPage;}
//---public ページ長を設定します
function setPageSize($page_size){$this->m_pageSize = $page_size;}
//--- publicページの長さを取得します
function getPageSize(){return $this->m_pageSize;}
//---public レコードの総数を取得します
function getCount(){return $this->m_num;}
// --- public で、総ページ数を取得します。 tcount ()%$ This- >getPageSize()>0)$page++;
// パラメータの説明: $url ページの呼び出し ex:http://hello.php?showtype=main
function show_navibar($recname="record",$first="Home",$pre="前のページ", $ Next = "次", $ last = "最後のページ") {
$ Showurl = Getenv ("Request_uri") O $ tmpos = strpos ($ showurl, "? Rscnt =");
IF ($ tmppos)
$ Showurl = Substr ($ showurl, 0, $ tmppos); Age = $ This ->getCurPage();
$pagecnt = $this->getPageCount();
$cnt = $this->getCount();
if($cnt return; // URL にはすでにパラメータがあります。
$url = $url."&";
?>
1>=$最初? =<?echo $ url。($ page-1)?>< href=>=$last?>
?> ;
=$next?> ?>
            
}
?>
共有 =$cnt?> =$recname?>,当前=$page?>/=$pagecnt?> 
>页




}
}



声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。