ページネーション
仕事中に書いたので、部署から全部投稿すると会社に申し訳ないので、フォームジャンプは削除しました。驚かないでください。 。 。
記述形式は比較的標準的です
PHPコード:------------------------------------- --- --------------------------------------------------- ---
/**********
| +------------------------------------------------ --
| クラス名: ページバー
| +------------------------------------------------ --
| 著者: Arvan [電子メール:Arvan@5n9.com QQ:8817776]
| 作成日: 2003-7-17
| 注:
| ページネーションのために行います
| +------------------------------------------------ --
| 警告: いいえ...
| +------------------------------------------------ --
**********/
class PageBar
{
var $total;
var $onepage;
var $num;
var $total_page;
var $linkhead;
function PageBar($ total, $onepage, $form_vars='')
{
$pagecount = $_GET['pagecount'];
$this->total = $total;
$this-> ;onepage = $onepage;
$this ->total_page = ceil($total/$onepage);
if (empty($pagecount))
{
$this->pagecount = 1;
$this-> ;offset = 0;
}
else
{
$this->pagecount = $pagecount;
$this->offset = ($pagecount-1)*$onepage;
}
if (!empty($ form_vars))
{
$vars =explode("|", $form_vars);
$chk = $vars[0];
$chk_value = $_POST['$chk'];
if (empty($chk_value) ))
{
$formlink = " ";
}
else
{
for ($i=0; $i
$var = $vars[$i];
$value = $_POST['$ var'];
$addchar = $vars."=".$value;
$addstr = $addstr.$addchar."&";
}
$formlink = "& ".substr($addstr, 0, sizeof($addstr)-1);
}
}
else
{
$formlink = "";
}
$linkarr =explode("pagecount=", $_SERVER ['QUERY_STRING']);
$ linkft = $linkarr[0];
if (empty($linkft))
{
$this->linkhead = $_SERVER['PHP_SELF']."?".$ formlink;
}
else
{
$this->linkhead = $_SERVER['PHP_SELF']."?".$linkft.$formlink;
}
}
#End function PageBar();
function offset()
{
return $this ->offset;
}
#関数の終了 offset();
function pre_page($char='')
{
$linkhead = $this->linkhead;
$ pagecount = $this->pagecount;
if (empty($char))
{
$char = "[<]";
}
if ($pagecount>1)
{
$pre_page = $pagecount - 1;
return "$char";
}
else
{
return ' ';
}
}
#終了関数 pre_page();
関数 next_page($char='')
{
$linkhead = $this->linkhead;
$total_page = $this->total_page;
$pagecount = $this-> pagecount;
if (empty($char ))
{
$char = "[>]";
}
if ($pagecount {
$next_page = $pagecount + 1;
return "< ;a href="$linkhead". "pagecount=$next_page">$char";
}
else
{
return ' ';
}
}
#End function next_page();
function num_bar($num='', $color='', $left='', $right='')
{
$num = (empty($num))?10:$num;
$this- >num = $num;
$mid = Floor($num/2);
$last = $num - 1;
$pagecount = $this->pagecount;
$totalpage = $this->total_page;
$linkhead = $this-> linkhead;
$left = (empty($left))?"[":$left;
$right = (empty($right))?"]":$right;
$color = (empty($color))?"#ff0000":$color;
$minpage = (($pagecount-$mid) $maxpage = $minpage + $last;
if ($maxpage>$totalpage )
{
$maxpage = $totalpage;
$minpage = $maxpage - $last;
$minpage = ($minpage }
for ($i=$minpage; $i< ;=$maxpage; $i++)
{
$char = $left.$i.$right;
if ($i==$pagecount)
{
$char = "";
}
$linkchar = "".$char."";
$ linkbar = $linkbar.$linkchar;
}
return $linkbar;
}
#End function num_bar();
function pre_group($char='')
{
$pagecount = $this->pagecount;
$linkhead = $this->linkhead;
$num = $this->num;
$mid = Floor($num/2);
$minpage = (($pagecount-$mid) $char = (empty($char))?"[<<]":$char;
$pgpagecount = ($minpage>$num)?$minpage-$mid:1;
return "".$char."";
}
#関数 pre_group() を終了;
function next_group($char='')
{
$ページカウント = $this->pagecount;
$linkhead = $this->linkhead;
$totalpage = $this->>total_page;
$num = $this->num;
$mid = Floor($num /2);
$last = $num;
$minpage = (($pagecount-$mid) $maxpage = $minpage + $last;
if ($maxpage>$totalpage)
{
$maxpage = $totalpage;
$minpage = $maxpage - $last ;
$minpage = ($minpage }
$char = (empty($char))?"[>>]":$char;
$ngpagecount = ($ totalpage>$maxpage+$last)?$maxpage + $mid:$totalpage;
return "".$char." ";
}
#終了 function next_group();
function Whole_num_bar($num='', $color='')
{
$num_bar = $this->num_bar($num, $color);
$pre_group = $this->pre_group();
$pre_page = $this->pre_page();
$next_page = $this->next_page();
$next_group = $this->next_group() ;
return $pre_group.$pre_page.$num_bar.$next_page.$next_group;
}
#End function Whole_bar();
}
#End class PageBar;
/*****
//例
$total = 1000;
$onepage = 20;
$pb = new PageBar($total, $onepage);
$offset = $pb->offset();
$ pagebar = $pb->whole_num_bar();
echo $offset."
".$pagebar;
return:
0
[<<] [1][2][3][4 ][5][6][7][8][9][10][>][>>]
*****/