Jump to content

Need help to get a Page limit <prev 123.. next>


SpikePR

Recommended Posts

Hi i have this listing and i try but my php are not good, so i need help to get a page limit on the that give me a result of rows limited by x number of rows, and give me a < Previous> 1 2 3 <next>

i don even not if it has it thank you for any help in advance.

 

the table list in issue is the =showtemp

 

<?php
function get_limited_description($str,$length)
{	
if(strlen($str) > $length)
	return substr($str,0,$length)."...";
else
	return $str;
}
$cat = $_GET['cat'];
//for showing products list
global $showsubtemp;
if((trim($cat) != "" || $showsubtemp != "")  && $mod == "")
{	
$products=$showsubtemp;
//echo $cat;
if($products=='Yes')
{
	$ext_query_str = "";
	if($_REQUEST['search_by'] != "" && isset($_REQUEST['search_by']))
		$ext_query_str = ' and pctbl.name like \'%'.$_REQUEST['search_by'].'%\' ';
	if ($cat != "")
		$ext_query_str .=  ' and pctbl.shop_category = \''.$cat.'\' ';

	$tableGlbCategories = DataTable_Query
	("
		SELECT  pctbl.*, pctbl.name as name_en,count(pctbl.id) as cc
		FROM 
		".$DBprefix."pm_products pctbl 
		WHERE 1=1  $ext_query_str
		group by pctbl.id 
	");
}
else
{
	$tableGlbCategories = DataTable_Query
	("
		SELECT  pctbl.id, pctbl.vFile ,pctbl.name_en ,count(ptbl.id) as cc
		FROM 
		".$DBprefix."hb_globalcategories pctbl 
		LEFT JOIN ".$DBprefix."pm_products ptbl ON
			pctbl.id = ptbl.shop_category 
		WHERE  pctbl.parent_id = '$cat' and pctbl.parent_id<>'0' 
		GROUP BY pctbl.id 
	");	
}
}
else
{
$tableGlbCategories = DataTable_Query
	("SELECT  
		pctbl.id, pctbl.parent_id, pctbl.vFile ,pctbl.active_en, pctbl.name_en, pctbl.description_en, pctbl.link_en, pctbl.username , count(cctbl.id) as cc
		FROM 
			 ".$DBprefix."hb_globalcategories pctbl LEFT JOIN ".$DBprefix."hb_globalcategories cctbl on 
		  	pctbl.id =cctbl.parent_id
		WHERE 
			pctbl.parent_id='0'
		GROUP BY pctbl.id
");//pctbl.. parent category table   and cctbl...child category table
}

if($products=='Yes')
{
$HTML .= "<table width=100%  border='0'>";
$iUserCounter = 0;
$iColumnsPerRow = 4;


		$HTML .= "<tr style=\"height:0px\" bgcolor=\"#33CC00\">";

				$HTML.="<td width=\"0%\"></td>";
				$HTML.="<td width=\"10%\"><font color=\"#FFFFFF\"><b>Imagen </b></font></td>";
				$HTML.="<td  width=\"33%\"><font color=\"#FFFFFF\"><b>Nombre</b></font></td>";
				$HTML.="<td  width=\"33%\"><font color=\"#FFFFFF\"><b>Descripción</b></font></td>";
				$HTML.="<td  width=\"10%\" align=\"LEFT\"><font color=\"#FFFFFF\"><b>Precio</b></font></td>";
				$HTML.="<td  width=\"10%\" align=\"CENTER\"><font color=\"#FFFFFF\"><b>Costo Envio</b></font></td>";
				$HTML.="<td  width=\"10%\" align=\"CENTER\"><font color=\"#FFFFFF\"><b>Peso</b></font></td>";
				$HTML.="<td  width=\"18%\" align=\"center\"><font color=\"#FFFFFF\"><b>Comprar</b></font></td>";
				$HTML.="<td width=\"0%\"></td>";
		$HTML .= "</tr>";

	//$HTML .= "<tr><td colspan=\"0\"></td>";

	while($tableGlbCategory = mysql_fetch_array($tableGlbCategories))
	{		
			if($c%2=='0')
				$bgcolor="#FFFFFF";
			else 
				$bgcolor="#E7F7E4";
		//print_r($tableGlbCategory);
		$HTML .= "<tr bgcolor=".$bgcolor.">";

				$HTML.="<td width=\"2%\"> </td>";
				$path= $_SERVER["HTTP_HOST"]."/tiendas.comerciopr.com/images/";

//$HTML.="<td><img src=\"images/".$tableGlbCategory["image_id"].".jpg\"  width=\"50\" height=\"30\" border=\"0\"></td>";

$str_link1 = "<a href=\"index.php?mod=product_details&ID=".$tableGlbCategory["id"]."&u=".$tableGlbCategory['username']."\">";

$str_link3 = "<a href=\"index.php?mod=product_details&ID=".$tableGlbCategory["id"]."&u=".$tableGlbCategory['username']."\">";
				$str_link = "<a href=\"index.php?mod=product_details&ID=".$tableGlbCategory["id"]."&u=".$tableGlbCategory['username']."\"><img src=\"http://".$_SERVER["HTTP_HOST"]."/image.php?id=".$tableGlbCategory["image_id"]."\"   width=\"60\" height=\"80\" border=\"0\"></a>";

				//$str_link = "<a href=\"index.php?mod=products&ID=".$tableGlbCategory["id"]."&u=".$tableGlbCategory['username']."\" target=\"_blank\"><img src=\"http://".$_SERVER["HTTP_HOST"]."/image.php?id=".$tableGlbCategory["image_id"]."\"   width=\"80\" height=\"60\" border=\"0\"></a>";

				$HTML.="<td>  ".$str_link."   </td>";
				//$HTML.="<td>".$tableGlbCategory["image_id"]."</td>";
				$HTML.="<td><font color=\"#3366CC\">".$str_link3."".$tableGlbCategory["name"]."</td>";
				$HTML.="<td>".get_limited_description($tableGlbCategory["description_short"],90)."</td>";
				$HTML.="<td width=\"8%\" align=\"right\"><B>\$</B>".$tableGlbCategory["price"]."</td>";
				$HTML.="<td width=\"10%\" align=\"right\">".$tableGlbCategory["shipping_cost"]."</td>";
				$HTML.="<td width=\"9%\" align=\"right\">".$tableGlbCategory["weight"]."</td>";
			 $HTML.="<td width=\"15%\" align=\"center\">".$str_link1."<img src=\"http://".$_SERVER["HTTP_HOST"]."/images/bin_15x54.png\"  border=\"0\"></td>";

$addTocartLink_str = "<a href=\"index.php?mod=products&ID=".$ID."&p=".$u."\"><img src=\"./images/comprar.gif\" border=\"0\" /></a>";

				$HTML.="<td> </td>";
		$HTML .= "</tr>";
		$c=$c+1;
		//$arrGlbCategories[$tableGlbCategory["id"]][name] = $tableGlbCategory["name"];
		//$arrGlbCategories[$tableGlbCategory["id"]][image] = $tableGlbCategory["image_id"];
		//$arrGlbCategories[$tableGlbCategory["id"]][discription] = $tableGlbCategory["discription_short"];
		//$arrGblCategoryValues[$tableGlbCategory["id"]] = $tableGlbCategory["cc"];
	}

	if($c==0)
	{
		$HTML .= "<tr><td colspan=\"7\" align=\"center\"><font color=\"#ff0000\">No se encontro ningun producto con esa frase <br><br> Trate de cambiar la frase</font></td>";		
	}

	$HTML .= "<tr><td colspan=\"7\"> </td>";

$HTML .= "</table>";
}

else if($RUNNING_MODE != 2)
{
$HTML .= "<table width=100%  border='0'>";
$HTML .= "<tr><td><table border='0'>";
$iUserCounter = 0;
$iColumnsPerRow = 4;

while($tableGlbCategory = mysql_fetch_array($tableGlbCategories))
{	
	$arrGlbCategories[$tableGlbCategory["id"]] = $tableGlbCategory["name_en"];
	$arrGblCategoryValues[$tableGlbCategory["id"]] = $tableGlbCategory["cc"];
	$arrGblCategoryFile[$tableGlbCategory["id"]] = $tableGlbCategory["vFile"];
}

	if(count($arrGlbCategories)>0)
	{
		$rowPerCol =count($arrGlbCategories)/4;	

		if($showtemp == 'Yes')
		{
			$HTML .= "<tr><td valign='top'><table border='0'>";
			$HTML .= "<tr><td valign='top' height='10'></td></tr>";	
		}
		$i = 0;

		while (list($key, $val) = each($arrGlbCategories)) 
		{	

			$vFile=$arrGblCategoryFile[$key];
			if($showtemp == 'Yes')
			{
				if($i%$rowPerCol==0 && $i != 0)
				{	
					$HTML .= "</table></td><td valign='top'> <table border='0'>";
				}
			}

			$HTML .= "<tr>";


			$iCatV = 0;
			if (array_key_exists($key, $arrGblCategoryValues)) 
			{	
				$iCatV = $arrGblCategoryValues[$key];
			}

			if($USE_MOD_REWRITE)
			{
				$strPLink = "http://www.".$DOMAIN_NAME."/category/".$key."/".format_str(stripslashes($val)).".html";
			}
			else
			{	
				if(trim($cat) != "")
					$strPLink = "index.php?cat=".$key."&g=1&showsubtemp=Yes";
					//$strPLink='';
				else
					$strPLink = "index.php?cat=".$key."&g=1&showtemp=Yes";
			}
			if($strPLink!='')
			{

				$HTML .= "<td valign=\"top\" width=".(100/$iColumnsPerRow)."% > ";
				if(is_file($CATEGORY_IMAGE_PATH.$vFile)){
					$cat_img_height = aParameter(8605);
					 $cat_img_width = aParameter(8606);
					if($showtemp == 'Yes')
					{	
						$HTML.="    <img src='".$CATEGORY_IMAGE_URL.$vFile."' height='".$cat_img_height."' width='".$cat_img_width."' align='absmiddle' > <br />";

					}
				}
				$HTML .= "    <img src=\"images/point.gif\" width=\"7\" height=\"7\" alt=\"\" border=\"0\">   <b><a href=\"".$strPLink."\">".stripslashes($val)."</a></b><span style='font-size:9px'></span>";
			}
/*				else
			{
				$HTML .= "<td valign=\"top\" width=".(100/$iColumnsPerRow)."% >  <img src=\"images/point.gif\" width=\"7\" height=\"7\" alt=\"\" border=\"0\">  <b><a alt=" href=\"".$strPLink."\">".stripslashes($val)."</a></b>   <span style='font-size:9px'></span>";

			}*/
			///////////////////////	
					$HTML.="<table>";
					$HTML.=getSubCategories($key);
					$HTML.="</table>";
					$HTML.="</td>";

			$HTML.="</td>";

			$HTML .= "</tr>";	
			if($showtemp == 'Yes')
				$HTML .= "<tr><td> </td></tr>";	
			$iUserCounter++;
			$i++;
		}
	}
	$HTML .= "</tr></table></td></tr>";
$HTML .= "</table>";

}

function getSubCategories($key)
{
//echo $key;
global $DBprefix;

///for not showing the sub-category for the main categories on the first page for that return if pid='0'
$table_pid=DataTable_Query("select distinct(parent_id) from ".$DBprefix."hb_globalcategories where id='".$key."'");
$pid='';
$pids='';
while($db_ids=mysql_fetch_array($table_pid))
{
	$pid=$db_ids['parent_id'];
}	
if($pid=='0')
	return;	

$tableGlbCategories_SUB = DataTable_Query
	("SELECT  
		pctbl.id, pctbl.parent_id, pctbl.active_en, pctbl.name_en, pctbl.description_en, pctbl.link_en, pctbl.username , count(cctbl.id) as cc
		FROM 
			 ".$DBprefix."hb_globalcategories pctbl LEFT JOIN ".$DBprefix."hb_globalcategories cctbl on 
		  	pctbl.id =cctbl.parent_id
		WHERE 
			pctbl.parent_id  ='".$key."' 
		GROUP BY pctbl.id
");

	while($tableGlbCategory_SUB = mysql_fetch_array($tableGlbCategories_SUB))
	{
		$arrGblCategoryValues_SUB[$tableGlbCategory_SUB["id"]] = $tableGlbCategory_SUB["name_en"];
		$arrGblCategoryValues_SUB[$tableGlbCategory_SUB["id"]] = $tableGlbCategory_SUB["name_en"];
	}
	if(count($arrGblCategoryValues_SUB)>0)
	{
		while (list($key1, $val1) = each($arrGblCategoryValues_SUB)) 
		{
			if($val1!='')
			{
				$cat1=$_GET['cat'];
				if(trim($cat1) != "")
					$strPLink1 = "index.php?showsubtemp=Yes&cat=".$key1."&g=1";
				else
					$strPLink1 = "index.php?cat=".$key1."&g=1";
				//http://tiendas.comerciopr.com/index.php?mod=products&cat=61&g=1
				$HTML1 .="<tr>";
				$HTML1 .= "<td valign=\"top\">        <img src=\"images/sub-bullet.gif\" align=\"middle\"><a href=\"".$strPLink1."\">".stripslashes($val1)."</a></b>   <span style='font-size:9px'></span>";
				$HTML1 .="</td>";

				$HTML1 .="</tr>";
			}

		}
	}
	return $HTML1;
}
?>

 

mod edit - coded tags added

Link to comment
Share on other sites

eeeeuuuuuuuccccccchhhhhh

 

can't be bothered to read all that BUT to get the number of pages that your pagination requires you need to divide the total number of items by the number of items per page and round it up..

 

like so...

 

<?php
$pages = ceil($items/$itemsperpage);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.