Location: PHPKode > scripts > Paging Class > paging-class/pagingClass.php
<?php
class PagingClass2
{
	var $tot_rec;			// Total records in DB  
	var $rec_per_page;		// Records per page to display
	var $tot_pages;			// Total Pages
	var $fix_page;			// Fix Page length to display
	var $html_code;			// Html Code for display


	/****	CONSTRUCTOR		****/
	function PagingClass2($tot_rec, $rec_per_page)
	{
		$this->tot_rec = $tot_rec;
		$this->rec_per_page = $rec_per_page;
		$this->tot_pages = ceil($this->tot_rec / $this->rec_per_page);
		$fix_page = 2;
		$this->html_code = "";
	}

	function DisplayPaging($curr_page)
	{
		$this->html_code = "<table align=center><tr><td>";
		
		// If user clicks on Page number 1
		if($curr_page == 1)
		{
			if($this->tot_pages == 1)
			{
				$this->html_code .= "<a href=\"paging.php?page=$this->tot_pages\">1&nbsp;&nbsp;&nbsp;</a>";
			}
			if($this->tot_pages == 2)
			{
				for($i = 1; $i <= $this->tot_pages; $i++)
				{
					$this->html_code .= "<a href=\"paging.php?page=$i\">$i&nbsp;&nbsp;&nbsp;</a>";
				}
			}
			if($this->tot_pages > 2)
			{
				for($i = 1; $i <= 2; $i++)
				{
					$this->html_code .= "<a href=\"paging.php?page=$i\">$i&nbsp;&nbsp;&nbsp;</a>";
				}
				$next = $i++;
				$this->html_code .= "<a href=\"paging.php?page=$next\">Next &nbsp;&nbsp;&nbsp;</a>";
			}
		}



		// If user clicks on Page number 2
		if($curr_page == 2)
		{
			if($this->tot_pages == 1)
			{
				$this->html_code .= "<a href=\"paging.php?page=$this->tot_pages\">1&nbsp;&nbsp;&nbsp;</a>";
			}
			if($this->tot_pages == 2)
			{
				for($i = 1; $i <= $this->tot_pages; $i++)
				{
					$this->html_code .= "<a href=\"paging.php?page=$i\">$i&nbsp;&nbsp;&nbsp;</a>";
				}
			}
			if($this->tot_pages > 2)
			{
				for($i = 1; $i <= 2; $i++)
				{
					$this->html_code .= "<a href=\"paging.php?page=$i\">$i&nbsp;&nbsp;&nbsp;</a>";
				}
				$next = $i++;
				$this->html_code .= "<a href=\"paging.php?page=$next\">Next &nbsp;&nbsp;&nbsp;</a>";
			}
		}


		// If user clicks on Page number greater then 2 (i.e 3+)
		if($curr_page >= 3)
		{
			if($this->tot_pages == $curr_page)
			{
				$prev = $curr_page - 2;

				$firstPg = $curr_page-1;

				$this->html_code .= "<a href=\"paging.php?page=$prev\">Prev&nbsp;&nbsp;&nbsp;</a>";
				$this->html_code .= "<a href=\"paging.php?page=$firstPg\">$firstPg&nbsp;&nbsp;&nbsp;</a>";
				$this->html_code .= "<a href=\"paging.php?page=$curr_page\">$curr_page&nbsp;&nbsp;&nbsp;</a>";
			}
			if($this->tot_pages > $curr_page)
			{
				$prev = $curr_page - 2;

				$firstPg = $curr_page-1;

				$next = $curr_page + 1;

				$this->html_code .= "<a href=\"paging.php?page=$prev\">Prev&nbsp;&nbsp;&nbsp;</a>";
				$this->html_code .= "<a href=\"paging.php?page=$firstPg\">$firstPg&nbsp;&nbsp;&nbsp;</a>";
				$this->html_code .= "<a href=\"paging.php?page=$curr_page\">$curr_page&nbsp;&nbsp;&nbsp;</a>";
				$this->html_code .= "<a href=\"paging.php?page=$next\">Next&nbsp;&nbsp;&nbsp;</a>";
			}
		}
		$this->html_code .= "</td></tr></table>";
		return $this->html_code;
	}
}
?>
Return current item: Paging Class