Reply to Re: SmartyPagine and mod_rewrite

Your name:

Reply:


Posted by CFC4N on 08/27/06 11:43

Cosmin Chiru 写道:

> Hello,
>
> I'm using SmartyPaginate to paginate results. Thing is I'm also using
> mod_rewrite for the entire site and the paginate link should look like
> this: "/products/pages/1". How can I do that? Thanks in advance.
==================================================
You can write a entire function or class !

E.G :

CLASS >>>>
class Pager{
//生成的页码(事实上不用也行)
var $pageNumber='';

//需要分类的条目总数
var $totalItems=0;
//数据连接相关
var $conn;
var $sql;
//每页显示几个条目
var $itemsPerPage=3;

//总页数
var $totalPageNumber=0;
//当前页码!
var $currentPageNumber=1;

//一个页面显示几个页码
var $length=10;


//需要分页的url
var $url='';
function
Pager($conn,$sql,$currentPageNumber,$itemsPerPage,$length,$url){
$this->currentPageNumber=$currentPageNumber;
$this->conn=$conn;
$this->sql=$sql;
$this->itemsPerPage=$itemsPerPage;
$this->length=$length;
$this->url=$url;
$this->url.=(stristr($this->url,'?')!=false)?'&':'?';
//Url里有"?"就加"&"没有就加"?"
$this->getTotalPageNumber();
}
function getTotalItems(){
//for adodb
$rs=$this->conn->Execute($this->sql);
$this->totalItems=$rs->RecordCount();
return $this->totalItems;
}
function getTotalPageNumber(){

$this->totalPageNumber=ceil($this->getTotalItems()/$this->itemsPerPage);

return $this->totalPageNumber;
}

//SQL里 LIMIT start,length 中的起始值
function getLimitStart(){
$start=($this->currentPageNumber-1)*$this->itemsPerPage;
return $start;
}
//SQL里 LIMIT start,length 中的length
function getLimitItems(){
return $this->itemsPerPage;
}
function getRsPerPage(){
$modiSQL=$this->sql." limit ".$this->getLimitStart()."
,".$this->getLimitItems();
//偶用的是adodb的说
$modiRS=$this->conn->Execute($modiSQL);
$arr=$modiRS->GetArray();
return $arr;
}

//主函数.中文分页
function getPageNumber(){
if ($this->getTotalPageNumber()>1){


$pageNumber='当前第'.$this->currentPageNumber.'页/共'.$this->totalPageNumber.'页';

//显示第一页和前一页
if ($this->currentPageNumber>1){
//第一页
//First Page
$pageNumber.="<B><A HREF=".$this->url."page=1>第一页</A>
</B> ";
//前一页
//Previous Page
$pageNumber.="<B><A
HREF=".$this->url."page=".($this->currentPageNumber-1).">前一页</A>
</B>";
}
//The start number is the first number of all pages which show
on the current page.

$startNumber=intval($this->currentPageNumber/$this->length)*$this->length;

//Prev N page
//交界处
if ($this->currentPageNumber>=$this->length){
$pageNumber.="[<B><A
HREF=".$this->url."page=".($startNumber-1).">".($startNumber-1)."</A></B>]...";

}

$leftPageNumber=0;
for ($i=$startNumber;$i<=$this->totalPageNumber;$i++){
if ($i==0)continue;
if ($i-$startNumber<$this->length){
if ($i==$this->currentPageNumber){
$pageNumber.="[<b>$i</b>]";
}else{
$pageNumber.="[<A
HREF=".$this->url."page=".$i.">".$i."</A>]";
}
}else{
$leftPageNumber=$this->totalPageNumber-$i+1;
break;
}
}
//显示下一个分页列表
if ($leftPageNumber>=1){
$pageNumber.="...[<B><A
HREF=".$this->url."page=".($startNumber+$this->length).">".($startNumber+$this->length)."</A></B>]
";
}

if ($this->currentPageNumber!=$this->totalPageNumber){
//Next page
$pageNumber.="<B><A
HREF=".$this->url."page=".($this->currentPageNumber+1).">下一页</A>
</B>";
//Last page
$pageNumber.="<B><A
HREF=".$this->url."page=".$this->totalPageNumber.">最后页</A> </B>";

}

$this->pageNumber=$pageNumber;
return $this->pageNumber;

}


}


//英文分页
function getPageNumber2(){
if ($this->getTotalPageNumber()>1){


$pageNumber='P'.$this->currentPageNumber.'/'.$this->totalPageNumber.'';

//显示第一页和前一页
if ($this->currentPageNumber>1){
//第一页
//First Page
$pageNumber.="<B><A HREF=".$this->url."page=1>FIRST</A>
</B> ";
//前一页
//Previous Page
$pageNumber.="<B><A
HREF=".$this->url."page=".($this->currentPageNumber-1).">PREV</A>
</B>";
}
//The start number is the first number of all pages which show
on the current page.

$startNumber=intval($this->currentPageNumber/$this->length)*$this->length;

//Prev N page
//交界处
if ($this->currentPageNumber>=$this->length){
$pageNumber.="[<B><A
HREF=".$this->url."page=".($startNumber-1).">".($startNumber-1)."</A></B>]...";

}

$leftPageNumber=0;
for ($i=$startNumber;$i<=$this->totalPageNumber;$i++){
if ($i==0)continue;
if ($i-$startNumber<$this->length){
if ($i==$this->currentPageNumber){
$pageNumber.="[<b>$i</b>]";
}else{
$pageNumber.="[<A
HREF=".$this->url."page=".$i.">".$i."</A>]";
}
}else{
$leftPageNumber=$this->totalPageNumber-$i+1;
break;
}
}
//显示下一个分页列表
if ($leftPageNumber>=1){
$pageNumber.="...[<B><A
HREF=".$this->url."page=".($startNumber+$this->length).">".($startNumber+$this->length)."</A></B>]
";
}

if ($this->currentPageNumber!=$this->totalPageNumber){
//Next page
$pageNumber.="<B><A
HREF=".$this->url."page=".($this->currentPageNumber+1).">NEXT</A>
</B>";
//Last page
$pageNumber.="<B><A
HREF=".$this->url."page=".$this->totalPageNumber.">LAST</A> </B>";
}

$this->pageNumber=$pageNumber;
return $this->pageNumber;

}


}

}
//$currentPageNumber=( isset($_GET['page']) ) ? intval($_GET['page']) :
1;
//include("PAGENUMBER/class.pagenumber.php");
//$pageNumber= new
PageNumber($adodbConn,$sql,$currentPageNumber,10,3,3,"test.php");
//echo $pageNumber->getPageNumber2();
//echo "<br>";
//echo $pageNumber->getPageNumber();
?>

FUNCTION >>>
function page($num, $perpage, $curr_page, $mpurl) {
$multipage = '';
if($num > $perpage) {
$page = 10;
$offset = 2;

$pages = ceil($num / $perpage);
$from = $curr_page - $offset;
$to = $curr_page + $page - $offset - 1;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
if($from < 1) {
$to = $curr_page + 1 - $from;
$from = 1;
if(($to - $from) < $page && ($to - $from) < $pages) {
$to = $page;
}
} elseif($to > $pages) {
$from = $curr_page - $pages + $to;
$to = $pages;
if(($to - $from) < $page && ($to - $from) < $pages) {
$from = $pages - $page + 1;
}
}
}
$multipage .= "<a href=\"$mpurl&page=1\"><font
face=webdings>9</font></a> ";
for($i = $from; $i <= $to; $i++) {
if($i != $curr_page) {
$multipage .= "<a href=\"$mpurl&page=$i\">$i</a> ";
} else {
$multipage .= '<u><b>'.$i.'</b></u> ';
}
}
$multipage .= $pages > $page ? " ... <a
href=\"$mpurl&page=$pages\">$pages</a> <a
href=\"$mpurl&page=$pages\"><Font face=webdings>:</font></a>" : " <a
href=\"$mpurl&page=$pages\"><Font face=webdings>:</font></a>";
}
//echo $multipage;
return $multipage;
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация