- UID
- 1
- 威望
- 1240 点
- 金钱
- 24019 金币
- 点卡
- 317 点
|
1#
发表于 2003-12-15 15:27
| 只看该作者
[转帖]分页类代码
作者:Arvan- /**********
- | +---------------------------------------------------
- | CLASS NAME: PageBar
- | +---------------------------------------------------
- | Author: Arvan [E-mail:Arvan@5n9.com QQ:8817776]
- | Create date: 2003-7-17
- | Note:
- | Do for pagination
- | +---------------------------------------------------
- | Warning: no...
- | +---------------------------------------------------
- **********/
- class PageBar
- {
- var $total;
- var $onepage;
- var $num;
- var $pagecount;
- var $total_page;
- var $offset;
- 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<sizeof($vars); $i++)
- {
- $var = $vars[$i];
- $value = $_POST["$var"];
- $addchar = $var."=".$value;
-
- $formlink = $formlink.$addchar."&";
- }
- }
- }
- else
- {
- $formlink = "";
- }
- $linkarr = explode("pagecount=", $_SERVER['QUERY_STRING']);
- $linkft = $linkarr[0];
- if (empty($linkft))
- {
- $this->linkhead = $_SERVER['PHP_SELF']."?".$formlink;
- }
- else
- {
- $linkft = (substr($linkft, -1)=="&")?$linkft:$linkft."&";
- $this->linkhead = $_SERVER['PHP_SELF']."?".$linkft.$formlink;
- }
- }
- #End function PageBar();
- function offset()
- {
- return $this->offset;
- }
- #End function offset();
- function pre_page($char='')
- {
- $linkhead = $this->linkhead;
- $pagecount = $this->pagecount;
- if (empty($char))
- {
- $char = "[<]";
- }
- if ($pagecount>1)
- {
- $pre_page = $pagecount - 1;
- return "<a href=\"$linkhead"."pagecount=$pre_page\">$char</a>";
- }
- else
- {
- return '';
- }
- }
- #End function pre_page();
- function next_page($char='')
- {
- $linkhead = $this->linkhead;
- $total_page = $this->total_page;
- $pagecount = $this->pagecount;
- if (empty($char))
- {
- $char = "[>]";
- }
- if ($pagecount<$total_page)
- {
- $next_page = $pagecount + 1;
- return "<a href=\"$linkhead"."pagecount=$next_page\">$char</a>";
- }
- 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)<1)?1:($pagecount-$mid);
- $maxpage = $minpage + $last;
- if ($maxpage>$totalpage)
- {
- $maxpage = $totalpage;
- $minpage = $maxpage - $last;
- $minpage = ($minpage<1)?1:$minpage;
- }
- for ($i=$minpage; $i<=$maxpage; $i++)
- {
- $char = $left.$i.$right;
- if ($i==$pagecount)
- {
- $char = "<font color='$color'>$char</font>";
- }
- $linkchar = "<a href='$linkhead"."pagecount=$i'>".$char."</a>";
- $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)<1)?1:($pagecount-$mid);
- $char = (empty($char))?"[<<]":$char;
- $pgpagecount = ($minpage>$num)?$minpage-$mid:1;
- return "<a href='$linkhead"."pagecount=$pgpagecount'>".$char."</a>";
- }
- #End function pre_group();
- function next_group($char='')
- {
- $pagecount = $this->pagecount;
- $linkhead = $this->linkhead;
- $totalpage = $this->total_page;
- $num = $this->num;
- $mid = floor($num/2);
- $last = $num;
- $minpage = (($pagecount-$mid)<1)?1:($pagecount-$mid);
- $maxpage = $minpage + $last;
- if ($maxpage>$totalpage)
- {
- $maxpage = $totalpage;
- $minpage = $maxpage - $last;
- $minpage = ($minpage<1)?1:$minpage;
- }
- $char = (empty($char))?"[>>]":$char;
- $ngpagecount = ($totalpage>$maxpage+$last)?$maxpage + $mid:$totalpage;
- return "<a href='$linkhead"."pagecount=$ngpagecount'>".$char."</a>";
- }
- #End 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();
-
- function Jump_form()
- {
- $linkhead = $this->linkhead;
- $total = $this->total_page;
- $form = <<<EOT
- <table width="100%" border="0" cellspacing="0" cellpadding="0">
- <script language="javascript">
- function jump(linkhead, total, page)
- {
- var pagecount = (page.value>total)?total:page.value;
- var pagecount = (pagecount<1)?1:pagecount;
- location.href = linkhead + "pagecount=" + pagecount;
-
- }
- </script>
- <form name="pagebarjumpform" method="post" onSubmit="return jump('$linkhead', $total, this.form.page)"><tr>
- <td>
- <input name="page" type="text" size="1">
- <input type="button" name="Submit" value="GO" onClick="return jump('$linkhead', $total, this.form.page)">
- </td>
- </tr></form></table>
- EOT;
- return $form;
- }
- #End function Jump_form();
- }
- #End class PageBar;
- /*****
- //example
- $total = 1000;
- $onepage = 20;
- $pb = new PageBar($total, $onepage);
- $offset = $pb->offset();
- $pagebar = $pb->whole_num_bar();
- $jumpform = $pb->Jump_form();
- echo $offset."<br>".$pagebar."<br>".$jumpform;
- return:
- 0
- [<<] [1][2][3][4][5][6][7][8][9][10][>][>>]
-
- *****/
复制代码 |
我是一个呼吸着现在的空气而生活在过去的人
这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
我已习惯了孤独,爱上孤独
他让我看清了自我,还原了自我
让我再静静的沉思中得到快乐和满足
再孤独的世界里我一遍又一遍
不厌其烦的改写着自己的过去
延伸到现在与未来
然而那只是泡沫般的美梦
产生的时刻又伴随着破灭的到来
在灰飞烟灭的瞬间我看到的是过程的美丽
而不是结果的悲哀。。。
|
|