- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
class PAGING
{
var $sql,$records,$pages;
var $page_no,$total,$limit,$first,$previous,$next,$last,$start,$end;
function PAGING($sql,$records=9,$pages=5)
{ global $mysqli;
if($pages%2==0) $pages++;
$res = $mysqli->query($sql);
$sqlquery++;
$total=mysqli_num_rows($res);
$page_no=isset($_GET["p"])?$_GET["p"]:1;
$limit=($page_no-1)*$records;
$sql.=" limit $limit,$records";
$first=1;
$previous=$page_no>1?$page_no-1:1;
$next=$page_no+1;
$last=ceil($total/$records);
if($next>$last)
$next=$last;
$start=$page_no;
$end=$start+$pages-1;
if($end>$last)
$end=$last;
if(($end-$start+1)<$pages)
{
$start-=$pages-($end-$start+1);
if($start<1)
$start=1;
}
if(($end-$start+1)==$pages)
{
$start=$page_no-floor($pages/2);
$end=$page_no+floor($pages/2);
while($start<$first)
{
$start++;
$end++;
}
while($end>$last)
{
$start--;
$end--;
}
}
$this->sql=$sql;
$this->records=$records;
$this->pages=$pages;
$this->page_no=$page_no;
$this->total=$total;
$this->limit=$limit;
$this->first=$first;
$this->previous=$previous;
$this->next=$next;
$this->last=$last;
$this->start=$start;
$this->end=$end;
}
function show_paging($url,$params=""){...}
}