class paging
{
var $max;
var $cur_page;
var $npages;
var $sql;
var $linkfile;
var $cur_limit;
var $prev;
var $next;
var $other_param;
function paging($max,$cpg,$npgs,$act,$sq,$nxt,$other_param=array())
{
$this->other_param=$other_param;
$this->max=$max;
$this->cur_page=$cpg;
$this->npages=$npgs;
$this->linkfile=$act;
$sq=stripslashes($sq);
$this->sql=$sq;
$this->next=$nxt;
if($this->cur_page==0)
$this->cnt_pages();
if($this->npages>1)
$this->disp_pageline();
//else print "
";
$this->calc_limit();
$this->sql=urldecode($this->sql);
$this->sql=stripslashes($this->sql);
$this->sql=ereg_replace("''","'",$this->sql);
$this->sql.=" limit $this->cur_limit,$this->max";
}
function cnt_pages()
{
$res=mysql_query($this->sql);
$count=mysql_num_rows($res);
$this->npages=$count/$this->max;
$intdec=explode('.',$this->npages);
if($intdec[1]>0)
$this->npages=$intdec[0]+1;
$this->cur_page=1;
}
function calc_limit()
{
$this->cur_limit=($this->cur_page-1)*$this->max;
}
function disp_pageline()
{
$lmax=5;
$this->sql=stripslashes($this->sql);
$this->sql=urlencode($this->sql);
$lines=$this->npages/$lmax;
$intdec=explode('.',$lines);
if($intdec[1]>0)
$lines=$intdec[0]+1;
$pagenoline="";
$start=$this->next*$lmax+1;
$end=($this->next+1)*$lmax;
if($end>$this->npages) $end=$this->npages;
if($this->next)
{
$this->prev=$this->next-1;
$i=$this->prev*$lmax+1;
$pagenoline.=$this->create_link('Prev',$i);
$pagenoline.=" ";
}
for($i=$start;$i<=$end;$i++)
{
if($i==$this->cur_page)
{
$pagenoline.="$i";
$pagenoline.=" ";
}
else
{
$pagenoline.=$this->create_link($i,$i);
$pagenoline.=" ";
}
}
$this->next+=1;
if($i<=$this->npages)
{
$pagenoline.=$this->create_link('Next',$i);
}
print "
Pages: $pagenoline |