<?php 

	// This the full code which will generate a paging system 
	$url= $_SERVER['PHP_SELF'].'?';
	$limit=10; // Limit of result per page 
	
	if ($_GET['tbtype']!=''){
		$tb_name=$_SESSION['SESS_ARR'][0][$_GET['tbtype']];}
	else{
		$currentFile = $_SERVER["PHP_SELF"];
		$tmppages = Explode('/', $currentFile);
		$tb_name= 'tb_'. str_replace(".php","",$tmppages[count($tmppages) - 1]);}
	if ($tb_name=='tb_customsolutions'){$tb_name='tb_customsolution';}
	if ($_SESSION['platid_temp']!='')
		{$qresult = getList("prod.product_id,prod.product_name,prod.product_brief_desc,prod.product_logo","tb_products prod,tb_supported_platform plat","where prod.product_id=plat.product_id AND plat.platform_id=".$_SESSION['platid_temp']);}
	elseif ($_SESSION['platid_cust']!='')
		{$qresult = getList("prod.custom_id,prod.product_name,prod.product_desc,prod.product_logo","tb_customsolution prod,tb_supported_customplat plat","where prod.custom_id=plat.custom_id AND plat.platform_id=".$_SESSION['platid_cust']);}
	else 
		{$qresult = getList('*',$tb_name,'');}	
	if ($_GET['tbtype']!='')
	{
		$url = $url . 'tbtype='.$_GET['tbtype'].'&&';
	}
	if ($_GET['page']!= '') {
		$pages=$_GET['page'];}
	else 
		{ $pages = 1;} //Get the current page 
	if ((trim($_GET['platid'])!='') || (trim($_SESSION['platid_temp'])!=''))
	{
		if (trim($_GET['platid'])!='') {$url_temp = 'platid='.$_GET['platid'].'&&';}
		if (trim($_SESSION['platid_temp'])!=''){$url_temp = 'platid='.$_SESSION['platid_temp'].'&&';}
		$url = $url.$url_temp;
	}
	$nrResults=mysql_num_rows($qresult); // Count the results 
	     
	if (($nrResults%$limit)<>0) { 
	$pmax=floor($nrResults/$limit)+1;  // Divide to total result by the number of query you want 
	// to display per page($limit) and create a Max page 
	} else { 
	$pmax=floor($nrResults/$limit); 
	} 
	if ($_SESSION['platid_temp']!='')
		{$qresult = getList("prod.product_id,prod.product_name,prod.product_brief_desc,prod.product_logo","tb_products prod,tb_supported_platform plat","where prod.product_id=plat.product_id AND plat.platform_id=".$_SESSION['platid_temp']. " LIMIT ".(($pages-1)*$limit).", $limit");}
	elseif($_GET['platid']!='')
		{$qresult = getList("prod.product_id,prod.product_name,prod.product_brief_desc,prod.product_logo","tb_products prod,tb_supported_platform plat","where prod.product_id=plat.product_id AND plat.platform_id=".$_GET['platid']. " LIMIT ".(($pages-1)*$limit).", $limit");}
	elseif ($_SESSION['platid_cust']!='')
		{$qresult = getList("prod.custom_id,prod.product_name,prod.product_desc,prod.product_logo","tb_customsolution prod,tb_supported_customplat plat","where prod.custom_id=plat.custom_id AND plat.platform_id=".$_SESSION['platid_cust']. " LIMIT ".(($pages-1)*$limit).", $limit");}
	else 
		{$qresult = getList('*',$tb_name," LIMIT ".(($pages-1)*$limit).", $limit");}
	//$qresult = getList('*',$_SESSION['SESS_ARR'][0][$_GET['tbtype']]," LIMIT ".(($_GET["page"]-1)*$limit).", $limit");
	//Need to generate query considering your limit 
	                 echo "<tr><td colspan='3' style='text-align:center'>Page: <br><br>"; // Make a simple css 
	 
	// We need to create a Previous page, so we need $pages to be bigger than 1, otherwise at the first page we would get a 0.  
	//For the previous to show up we need at least to be at the second page. 
	if($pages > 1) { 
	$prevp="<a href='".$url."page=".($pages-1)."' title='Previous Page'>Prev</a>&nbsp;&nbsp;&nbsp;&nbsp;"; } else {echo "";}     
	echo $prevp;  
	// Here We want create a page from the results we got by dividing the total by the the limit. So let say you got 
	//45 results and you want 5 results per page; these simple lines will create you 8 pages. 
	$pid=1;  
	while ($pid<=$pmax) {  
	$paging= "<a href='".$url."page=$pid' title='Page $pid of $pmax'> $pid</a>&nbsp;&nbsp;&nbsp;&nbsp;"; 
	//So here, let say we are at the 3rd page and we want the 3 to be blank so the user can know where is he now. 
	//This will act as Current Page! We need to replace the url by a text 
	$newpaging=str_replace("<a href='".$url."page=$pages' title='Page $pages of $pmax'> $pages</a>&nbsp;&nbsp;&nbsp;&nbsp;", "<span>$pages</span>&nbsp;&nbsp;&nbsp;&nbsp;", $paging); 
	echo $newpaging; 
	 
	$pid++;  // create pages until reach the result 
	}   
	//We want to create a next page and a last page, $pages have to be less than $pmax. 
	if($pages < $pmax) { 
	$nextp="<a href='".$url."page=".($pages+1)."' title='Next Page'>Next</a>&nbsp;&nbsp;&nbsp;&nbsp;"; } else {echo "";}     
	echo $nextp; 
	//echo  "<a href='".$url."page=$pmax' title='Last Page'>Last Page</a>&nbsp;&nbsp;&nbsp;&nbsp;"; 
	echo "</td></tr>"; 
?> 
